Skip to content

Commit

Permalink
test: refactor test/e2e/states.test.js
Browse files Browse the repository at this point in the history
WIP: will rename the test and clean it up after i received a feedback from maintainers
  • Loading branch information
mahdikhashan committed May 12, 2024
1 parent e690789 commit f371ae6
Show file tree
Hide file tree
Showing 10 changed files with 152 additions and 0 deletions.
@@ -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();
}
})
})

});

0 comments on commit f371ae6

Please sign in to comment.