Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: refactor e2e tests to playwright #5080

Draft
wants to merge 72 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
13c06af
chore: setup playwright
mahdikhashan Mar 1, 2024
18e0e30
chore: disable parallel test running
mahdikhashan Mar 1, 2024
91ad989
feat: remove example test from playwright setup step
mahdikhashan Mar 1, 2024
2f97665
test: refactor test/e2e/states.test.js
mahdikhashan Mar 1, 2024
5f44a78
chore(deps): bump html-entities from 2.4.0 to 2.5.0 (#5083)
dependabot[bot] Mar 4, 2024
1c20920
chore(deps-dev): bump cspell from 8.4.1 to 8.5.0 (#5082)
dependabot[bot] Mar 4, 2024
d58d557
chore(deps): bump express from 4.18.2 to 4.18.3 (#5078)
dependabot[bot] Mar 4, 2024
3790bec
chore(deps-dev): bump @types/node from 20.11.22 to 20.11.24 (#5079)
dependabot[bot] Mar 4, 2024
cddf382
chore(deps-dev): bump @babel/preset-env from 7.23.9 to 7.24.0 (#5075)
dependabot[bot] Mar 4, 2024
1e97fe0
chore(deps): bump html-entities from 2.5.0 to 2.5.2 (#5087)
dependabot[bot] Mar 5, 2024
2aed762
refactor: add 'mode' property in second array object in examples (#5…
ayushkumarbhadani Mar 5, 2024
71e5e9f
docs: fix migration guide (#5089)
alexander-akait Mar 5, 2024
a8cdccd
chore(deps-dev): bump puppeteer from 22.3.0 to 22.4.0 (#5090)
dependabot[bot] Mar 6, 2024
53de75d
chore(deps-dev): bump cspell from 8.5.0 to 8.6.0 (#5091)
dependabot[bot] Mar 6, 2024
2201442
chore(deps): update (#5096)
alexander-akait Mar 7, 2024
c6a3586
chore(deps-dev): bump puppeteer from 22.4.0 to 22.4.1 (#5099)
dependabot[bot] Mar 11, 2024
8ea7cb8
chore(deps): bump open from 10.0.4 to 10.1.0 (#5100)
dependabot[bot] Mar 11, 2024
6e1aed3
fix(types): proxy (#5101)
alexander-akait Mar 11, 2024
37f4760
chore(deps-dev): bump @types/node from 20.11.25 to 20.11.26 (#5102)
dependabot[bot] Mar 12, 2024
08cab58
chore(release): 5.0.3
alexander-akait Mar 12, 2024
ba9dfb6
chore(deps-dev): bump @commitlint/cli from 19.0.3 to 19.1.0 (#5103)
dependabot[bot] Mar 13, 2024
fb6f22a
chore(deps-dev): bump @commitlint/config-conventional (#5104)
dependabot[bot] Mar 13, 2024
aab576a
fix(security): bump webpack-dev-middleware (#5112)
alexander-akait Mar 19, 2024
64a1860
chore(release): 5.0.4
alexander-akait Mar 19, 2024
92a1bfd
chore(deps-dev): bump webpack from 5.90.3 to 5.91.0 (#5119)
dependabot[bot] Mar 21, 2024
04e5695
chore(deps): bump express from 4.18.3 to 4.19.1 (#5117)
dependabot[bot] Mar 21, 2024
7e6f046
chore(deps-dev): bump typescript from 5.4.2 to 5.4.3 (#5116)
dependabot[bot] Mar 21, 2024
af6bd68
chore(deps): bump webpack-dev-middleware from 7.1.0 to 7.1.1 (#5121)
dependabot[bot] Mar 22, 2024
12d0fec
chore(deps-dev): bump @babel/preset-env from 7.24.1 to 7.24.3 (#5118)
dependabot[bot] Mar 22, 2024
edbc6e1
chore(deps-dev): bump @babel/core from 7.24.1 to 7.24.3 (#5115)
dependabot[bot] Mar 22, 2024
b48c59d
ci: update codecov action to v4 (#5122)
snitin315 Mar 25, 2024
294400a
chore(deps-dev): bump puppeteer from 22.5.0 to 22.6.0 (#5114)
dependabot[bot] Mar 25, 2024
6b31b7f
chore(deps): bump express from 4.19.1 to 4.19.2 (#5124)
dependabot[bot] Mar 26, 2024
c72d437
chore(deps-dev): bump puppeteer from 22.6.0 to 22.6.1 (#5125)
dependabot[bot] Mar 26, 2024
7989ec7
chore(deps-dev): bump cspell from 8.6.0 to 8.6.1 (#5123)
dependabot[bot] Mar 26, 2024
1d1232f
chore(deps): bump webpack-dev-middleware from 7.1.1 to 7.2.0 (#5126)
dependabot[bot] Apr 2, 2024
a175b13
chore(deps-dev): bump @types/node from 20.11.30 to 20.12.2 (#5127)
dependabot[bot] Apr 2, 2024
1c38253
chore(deps-dev): bump memfs from 4.8.0 to 4.8.1 (#5128)
dependabot[bot] Apr 2, 2024
ab6fb70
chore(deps): bump webpack-dev-middleware from 7.2.0 to 7.2.1 (#5131)
dependabot[bot] Apr 3, 2024
b5e81cd
chore(deps): bump @types/serve-static from 1.15.5 to 1.15.7 (#5133)
dependabot[bot] Apr 3, 2024
fec7c25
chore(deps-dev): bump @types/node from 20.12.2 to 20.12.3 (#5132)
dependabot[bot] Apr 3, 2024
7110a26
chore(deps-dev): bump @babel/plugin-transform-runtime (#5120)
dependabot[bot] Apr 3, 2024
e13d3ae
chore(deps-dev): bump puppeteer from 22.6.1 to 22.6.2 (#5130)
dependabot[bot] Apr 3, 2024
760657d
chore(deps-dev): bump css-loader from 6.10.0 to 6.11.0 (#5139)
dependabot[bot] Apr 4, 2024
f3788a0
chore(deps-dev): bump @types/node from 20.12.3 to 20.12.4 (#5137)
dependabot[bot] Apr 4, 2024
9fddbb9
chore(deps-dev): bump @babel/preset-env from 7.24.3 to 7.24.4 (#5135)
dependabot[bot] Apr 4, 2024
c5aa7aa
chore(deps-dev): bump @types/node from 20.12.4 to 20.12.5 (#5144)
dependabot[bot] Apr 8, 2024
b318063
chore(deps-dev): bump @types/node from 20.12.5 to 20.12.7 (#5146)
dependabot[bot] Apr 10, 2024
767b493
chore: upgrading express from version 4.17.3 to version 4.19.2 due to…
codingwithbenny Apr 11, 2024
7c42ea0
chore(deps-dev): bump cspell from 8.6.1 to 8.7.0 (#5148)
dependabot[bot] Apr 11, 2024
f661407
chore(deps-dev): bump @commitlint/cli from 19.2.1 to 19.2.2 (#5151)
dependabot[bot] Apr 16, 2024
1a81676
chore(deps-dev): bump memfs from 4.8.1 to 4.8.2 (#5152)
dependabot[bot] Apr 16, 2024
31d9d77
chore(deps-dev): bump @babel/core from 7.24.3 to 7.24.4 (#5136)
dependabot[bot] Apr 17, 2024
5c8544c
chore(deps-dev): bump marked from 12.0.1 to 12.0.2 (#5160)
dependabot[bot] Apr 22, 2024
c9f3bd4
chore(deps-dev): bump core-js from 3.36.1 to 3.37.0 (#5155)
dependabot[bot] Apr 22, 2024
d1fcc72
chore(deps-dev): bump @babel/runtime from 7.24.1 to 7.24.4 (#5138)
dependabot[bot] Apr 22, 2024
be8a832
chore(deps): bump ipaddr.js from 2.1.0 to 2.2.0 (#5159)
dependabot[bot] Apr 24, 2024
1a1561f
fix: replace `rimraf` with `rm` (#5162)
askoufis Apr 24, 2024
3096148
feat: added the `app` option to setup any `connect` compatibility HTT…
alexander-akait Apr 24, 2024
a3ced4d
ci: add Node v22 (#5164)
snitin315 May 7, 2024
69e21f1
chore: setup playwright
mahdikhashan Mar 1, 2024
9a1b7e7
chore: disable parallel test running
mahdikhashan Mar 1, 2024
e690789
feat: remove example test from playwright setup step
mahdikhashan Mar 1, 2024
f371ae6
test: refactor test/e2e/states.test.js
mahdikhashan Mar 1, 2024
8c663b0
Merge remote-tracking branch 'origin/issue-2843/refactor-e2e-tests-fr…
mahdikhashan May 12, 2024
e0cdf7d
chore: add playwright after it was removed by merge conflicts
mahdikhashan May 12, 2024
8f5fdac
chore: initial config for playwright
mahdikhashan May 12, 2024
82b52a8
test: remove old snapshots
mahdikhashan May 12, 2024
a80179c
fix: move `playwright` requires after `webpack` to fix eslint warning
mahdikhashan May 12, 2024
dd27f0e
chore: disable parallel config for playwright
mahdikhashan May 12, 2024
a5cc37e
test: snapshots for `stats.test.js`
mahdikhashan May 12, 2024
edb93fc
chore: make env CI variable a constant
mahdikhashan May 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Expand Up @@ -21,3 +21,7 @@ test/fixtures/watch-files-config/public/assets/non-exist.txt
test/fixtures/reload-config/main.css
test/fixtures/reload-config-2/main.css
!/test/fixtures/static-config/public/node_modules
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
60 changes: 60 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -41,6 +41,7 @@
"test:coverage": "npm run test:only -- --coverage",
"test:watch": "npm run test:coverage --watch",
"test": "npm run test:coverage",
"test:playwright": "npx playwright test",
"pretest": "npm run lint",
"prepare": "husky && npm run build",
"release": "standard-version"
Expand Down Expand Up @@ -87,6 +88,7 @@
"@babel/runtime": "^7.22.5",
"@commitlint/cli": "^18.5.0",
"@commitlint/config-conventional": "^18.5.0",
"@playwright/test": "^1.42.0",
"@types/compression": "^1.7.2",
"@types/default-gateway": "^3.0.1",
"@types/node": "^20.11.16",
Expand Down
77 changes: 77 additions & 0 deletions playwright.config.ts
@@ -0,0 +1,77 @@
import { defineConfig, devices } from "@playwright/test";

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// require('dotenv').config();

/**q
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: "./test/e2e-playwright",
/* Run tests in files in parallel */
fullyParallel: false,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: 0,
/* Opt out of parallel tests on CI. */
workers: undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: "html",
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
// baseURL: 'http://127.0.0.1:3000',

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: "on-first-retry",
},

/* Configure projects for major browsers */
projects: [
{
name: "chromium",
use: { ...devices["Desktop Chrome"] },
},

// {
// name: 'firefox',
// use: { ...devices['Desktop Firefox'] },
// },

// {
// name: 'webkit',
// use: { ...devices['Desktop Safari'] },
// },

/* Test against mobile viewports. */
// {
// name: 'Mobile Chrome',
// use: { ...devices['Pixel 5'] },
// },
// {
// name: 'Mobile Safari',
// use: { ...devices['iPhone 12'] },
// },

/* Test against branded browsers. */
// {
// name: 'Microsoft Edge',
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
// },
// {
// name: 'Google Chrome',
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
// },
],

/* Run your local dev server before starting the tests */
// webServer: {
// command: 'npm run start',
// url: 'http://127.0.0.1:3000',
// reuseExistingServer: !process.env.CI,
// },
});
@@ -0,0 +1 @@
["[webpack-dev-server] Server started: Hot Module Replacement enabled, Live Reloading enabled, Progress disabled, Overlay enabled.","[HMR] Waiting for update signal from WDS...","Hey."]
@@ -0,0 +1 @@
["[webpack-dev-server] Server started: Hot Module Replacement enabled, Live Reloading enabled, Progress disabled, Overlay enabled.","[HMR] Waiting for update signal from WDS...","Hey."]
@@ -0,0 +1 @@
["[webpack-dev-server] Server started: Hot Module Replacement enabled, Live Reloading enabled, Progress disabled, Overlay enabled.","[HMR] Waiting for update signal from WDS...","Hey."]
@@ -0,0 +1 @@
["[webpack-dev-server] Server started: Hot Module Replacement enabled, Live Reloading enabled, Progress disabled, Overlay enabled.","[HMR] Waiting for update signal from WDS...","Hey."]
@@ -0,0 +1 @@
["[webpack-dev-server] Server started: Hot Module Replacement enabled, Live Reloading enabled, Progress disabled, Overlay enabled.","[HMR] Waiting for update signal from WDS...","Hey."]
@@ -0,0 +1 @@
["[webpack-dev-server] Server started: Hot Module Replacement enabled, Live Reloading enabled, Progress disabled, Overlay enabled.","[HMR] Waiting for update signal from WDS...","Hey."]
@@ -0,0 +1 @@
["[webpack-dev-server] Server started: Hot Module Replacement enabled, Live Reloading enabled, Progress disabled, Overlay enabled.","[HMR] Waiting for update signal from WDS...","Hey."]
@@ -0,0 +1 @@
["[webpack-dev-server] Server started: Hot Module Replacement enabled, Live Reloading enabled, Progress disabled, Overlay enabled.","[HMR] Waiting for update signal from WDS...","Hey."]
@@ -0,0 +1 @@
["[webpack-dev-server] Server started: Hot Module Replacement enabled, Live Reloading enabled, Progress disabled, Overlay enabled.","[HMR] Waiting for update signal from WDS...","Hey."]
143 changes: 143 additions & 0 deletions test/e2e-playwright/stats-refactored.test.js
@@ -0,0 +1,143 @@
"use strict";

const webpack = require("webpack");
const Server = require("../../lib/Server");
const config = require("../fixtures/client-config/webpack.config");
const HTMLGeneratorPlugin = require("../helpers/html-generator-plugin");
const port = require("../ports-map").stats;
const { test } = require("@playwright/test");
const { describe } = require("@playwright/test");
const { expect } = require("@playwright/test");

describe("stats", () => {
const cases = [
{
title: 'should work when "stats" is not specified',
webpackOptions: {},
},
{
title: 'should work using "{}" value for the "stats" option',
webpackOptions: {
stats: {},
},
},
{
title: 'should work using "undefined" value for the "stats" option',
webpackOptions: {
// eslint-disable-next-line no-undefined
stats: undefined,
},
},
{
title: 'should work using "false" value for the "stats" option',
webpackOptions: {
stats: false,
},
},
{
title: 'should work using "errors-only" value for the "stats" option',
webpackOptions: {
stats: "errors-only",
},
},
{
title:
'should work using "{ assets: false }" value for the "stats" option',
webpackOptions: {
stats: {
assets: false,
},
},
},
{
title:
'should work using "{ colors: { green: "\u001b[32m" }}" value for the "stats" option',
webpackOptions: {
stats: {
colors: {
green: "\u001b[32m",
},
},
},
},
{
title:
'should work using "{ warningsFilter: \'test\' }" value for the "stats" option',
webpackOptions: {
plugins: [
{
apply(compiler) {
compiler.hooks.thisCompilation.tap(
"warnings-webpack-plugin",
(compilation) => {
compilation.warnings.push(
new Error("Warning from compilation"),
);
},
);
},
},
new HTMLGeneratorPlugin(),
],
stats: { warningsFilter: /Warning from compilation/ },
},
},
];

if (webpack.version.startsWith("5")) {
cases.push({
title: 'should work and respect the "ignoreWarnings" option',
webpackOptions: {
plugins: [
{
apply(compiler) {
compiler.hooks.thisCompilation.tap(
"warnings-webpack-plugin",
(compilation) => {
compilation.warnings.push(
new Error("Warning from compilation"),
);
},
);
},
},
new HTMLGeneratorPlugin(),
],
ignoreWarnings: [/Warning from compilation/],
},
});
}

cases.forEach((testCase) => {
test(testCase.title, async ({ page }) => {
const compiler = webpack({ ...config, ...testCase.webpackOptions });
const devServerOptions = {
port,
};
const server = new Server(devServerOptions, compiler);

await server.start();

try {
const consoleMessages = [];

page.on("console", (message) => {
consoleMessages.push(message);
});

await page.goto(`http://localhost:${port}/`, {
waitUntil: "networkidle0",
});

expect(
JSON.stringify(consoleMessages.map((message) => message.text())),
).toMatchSnapshot();
} catch (error) {
throw error;
} finally {
await server.stop();
}
})
})

});