vite-plugin-package-version/__tests__/version.js
2021-04-22 22:52:14 +02:00

47 lines
1,014 B
JavaScript

const puppeteer = require('puppeteer');
const { setup, teardown } = require('jest-dev-server');
let browser;
let page;
beforeAll(async () => {
browser = await puppeteer.launch();
page = await browser.newPage();
return setup([
{
command: 'npm run demo:dev',
port: 3000,
},
{
command: 'npm run demo:prod',
port: 3001,
},
]);
});
afterAll(async () => {
browser.close();
await teardown();
});
describe('import.meta.env contains PACKAGE_VERSION', () => {
test('in development', async () => {
await page.goto('http://localhost:3000/');
const element = await page.$('#PACKAGE_VERSION');
const version = await element.evaluate((el) => el.textContent);
expect(version).toBe('0.0.0');
});
test('in production', async () => {
await page.goto('http://localhost:3001/');
const element = await page.$('#PACKAGE_VERSION');
const version = await element.evaluate((el) => el.textContent);
expect(version).toBe('0.0.0');
});
});