Replace Saucelabs with Playwright
Also reorganized npm scripts.
This commit is contained in:
committed by
Jay Linski
parent
ef0fc290b9
commit
9ed9418488
@@ -0,0 +1,10 @@
|
||||
module.exports = {
|
||||
root: true,
|
||||
extends: ['eslint:recommended', 'prettier'],
|
||||
env: {
|
||||
node: true
|
||||
},
|
||||
parserOptions: {
|
||||
ecmaVersion: 6
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,5 @@
|
||||
module.exports = {
|
||||
parserOptions: {
|
||||
ecmaVersion: 2020
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,14 @@
|
||||
# Browser Tests with Playwright
|
||||
|
||||
These tests execute Mocha tests from the `spec`-folder in multiple browsers.
|
||||
|
||||
## Using Docker
|
||||
|
||||
Execute the following commands in the project root:
|
||||
|
||||
```bash
|
||||
npm install
|
||||
npx grunt prepare
|
||||
docker pull mcr.microsoft.com/playwright:focal
|
||||
docker run -it --rm --volume $(pwd):/srv/app --workdir /srv/app --ipc=host mcr.microsoft.com/playwright:focal npm run test:browser
|
||||
```
|
||||
@@ -0,0 +1,27 @@
|
||||
const { devices } = require('@playwright/test');
|
||||
|
||||
/** @type {import('@playwright/test').PlaywrightTestConfig} */
|
||||
const config = {
|
||||
projects: [
|
||||
{
|
||||
name: 'chromium',
|
||||
use: { ...devices['Desktop Chrome'] }
|
||||
},
|
||||
{
|
||||
name: 'firefox',
|
||||
use: { ...devices['Desktop Firefox'] }
|
||||
},
|
||||
{
|
||||
name: 'webkit',
|
||||
use: { ...devices['Desktop Safari'] }
|
||||
}
|
||||
],
|
||||
reporter: 'list',
|
||||
webServer: {
|
||||
command: 'npm run test:serve',
|
||||
port: 3000,
|
||||
reuseExistingServer: false
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = config;
|
||||
@@ -0,0 +1,33 @@
|
||||
const { test, expect } = require('@playwright/test');
|
||||
|
||||
async function waitForMochaAndAssertResult(page) {
|
||||
await page.waitForFunction(() => window.mochaResults); // eslint-disable-line no-undef
|
||||
const mochaResults = await page.evaluate('window.mochaResults');
|
||||
|
||||
expect(mochaResults.failures).toBe(0);
|
||||
}
|
||||
|
||||
test('Spec handlebars.js', async ({ page, baseURL }) => {
|
||||
await page.goto(`${baseURL}/spec/?headless=true`);
|
||||
await waitForMochaAndAssertResult(page);
|
||||
});
|
||||
|
||||
test('Spec handlebars.amd.js (AMD)', async ({ page, baseURL }) => {
|
||||
await page.goto(`${baseURL}/spec/amd.html?headless=true`);
|
||||
await waitForMochaAndAssertResult(page);
|
||||
});
|
||||
|
||||
test('Spec handlebars.runtime.amd.js (AMD)', async ({ page, baseURL }) => {
|
||||
await page.goto(`${baseURL}/spec/amd-runtime.html?headless=true`);
|
||||
await waitForMochaAndAssertResult(page);
|
||||
});
|
||||
|
||||
test('Spec handlebars.js (UMD)', async ({ page, baseURL }) => {
|
||||
await page.goto(`${baseURL}/spec/umd.html?headless=true`);
|
||||
await waitForMochaAndAssertResult(page);
|
||||
});
|
||||
|
||||
test('Spec handlebars.runtime.js (UMD)', async ({ page, baseURL }) => {
|
||||
await page.goto(`${baseURL}/spec/umd-runtime.html?headless=true`);
|
||||
await waitForMochaAndAssertResult(page);
|
||||
});
|
||||
Executable
+36
@@ -0,0 +1,36 @@
|
||||
const fs = require('fs');
|
||||
const http = require('http');
|
||||
const path = require('path');
|
||||
|
||||
const mimeTypes = {
|
||||
css: 'text/css',
|
||||
html: 'text/html',
|
||||
js: 'text/javascript',
|
||||
json: 'application/json'
|
||||
};
|
||||
|
||||
// Serve static files for spec tests
|
||||
http
|
||||
.createServer(function(req, res) {
|
||||
const url = new URL(req.url, `http://${req.headers.host}`);
|
||||
let filePath = `${path.resolve(__dirname, '..')}${url.pathname}`;
|
||||
|
||||
if (fs.existsSync(filePath) && fs.statSync(filePath).isDirectory()) {
|
||||
filePath += filePath.endsWith('/') ? '' : '/';
|
||||
filePath += 'index.html';
|
||||
}
|
||||
|
||||
fs.readFile(filePath, function(err, data) {
|
||||
if (err) {
|
||||
res.writeHead(404);
|
||||
res.end(JSON.stringify(err));
|
||||
return;
|
||||
}
|
||||
|
||||
let mimeType = mimeTypes[filePath.split('.').pop()] || 'text/plain';
|
||||
|
||||
res.writeHead(200, { 'Content-Type': mimeType });
|
||||
res.end(data);
|
||||
});
|
||||
})
|
||||
.listen(3000);
|
||||
Reference in New Issue
Block a user