Skip to content

Commit

Permalink
Update to webpack@5.42.0 (#723)
Browse files Browse the repository at this point in the history
* webpack@5.42.0 update

* update tests

* update timeouts

* update jest

* remove duplicated test

* separate integration tests

* fixup integration test

* try add teardown timeout

* try increase teardown timeout

* bisect on cli / integration tests

* fixup bisect

* reduce timeouts

* bisect down to watcher, remove timeouts

* increase jest watcher timeout

* try node 14.17.2

* use check latest for nodejs

* reinstate all tests

* Revert "reinstate all tests"

This reverts commit 1264641.

* webpack@5.42.1

* add teardown timeout

* try defer unhandled rejections

* note unhandled rejections

* add completion delay

* add logging

* try non-sensical stackoverflow answer

* note all unhandled rejections

* easier debugging

* fixup workflow

* remove fake timers

* process exit

* next attempt

* try all integration tests

* reinstate full testing
  • Loading branch information
guybedford committed Jul 6, 2021
1 parent a529543 commit 2ba1c22
Show file tree
Hide file tree
Showing 10 changed files with 1,145 additions and 888 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Expand Up @@ -27,6 +27,7 @@ jobs:
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}
check-latest: true
- name: Print Node Version
run: node --version
- name: Install Dependencies
Expand Down
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -61,7 +61,7 @@
"hot-shots": "^5.9.2",
"ioredis": "^4.2.0",
"isomorphic-unfetch": "^3.0.0",
"jest": "^26.3.0",
"jest": "^27.0.6",
"jimp": "^0.5.6",
"jugglingdb": "2.0.1",
"koa": "^2.6.2",
Expand Down Expand Up @@ -110,7 +110,7 @@
"vue": "^2.5.17",
"vue-server-renderer": "^2.5.17",
"web-vitals": "^0.2.4",
"webpack": "5.36.2",
"webpack": "5.42.1",
"when": "^3.7.8"
},
"resolutions": {
Expand Down
33 changes: 33 additions & 0 deletions test/cli.test.js
@@ -0,0 +1,33 @@
const fs = require("fs");
const { fork } = require("child_process");
const coverage = global.coverage;

jest.setTimeout(20000);

for (const cliTest of eval(fs.readFileSync(__dirname + "/cli.js").toString())) {
it(`should execute "ncc ${(cliTest.args || []).join(" ")}"`, async () => {
const ps = fork(__dirname + (coverage ? "/../src/cli.js" : "/../dist/ncc/cli.js"), cliTest.args || [], {
stdio: "pipe",
env: { ...process.env, ...cliTest.env },
});
let stderr = "", stdout = "";
ps.stderr.on("data", chunk => stderr += chunk.toString());
ps.stdout.on("data", chunk => stdout += chunk.toString());
const expected = cliTest.expect || { code: 0 };
let timedOut = false;
if (cliTest.timeout)
setTimeout(() => {
timedOut = true;
ps.kill();
}, cliTest.timeout);
const code = await new Promise(resolve => ps.on("close", resolve));
if (typeof expected === "function")
expect(expected(code, stdout, stderr, timedOut)).toBe(true);
else {
if ("code" in expected)
expect(code).toBe(expected.code);
if ("timeout" in expected)
expect(timedOut).toBe(true);
}
});
}
210 changes: 0 additions & 210 deletions test/index.test.js

This file was deleted.

112 changes: 112 additions & 0 deletions test/integration.test.js
@@ -0,0 +1,112 @@
const os = require("os");
const fs = require("fs");
const path = require("path");
const coverage = global.coverage;

// the twilio test can take a while (large codebase)
jest.setTimeout(200000);

let nccRun;
if (coverage) {
nccRun = require(__dirname + "/../src/cli.js");
}
else {
nccRun = require(__dirname + "/../dist/ncc/cli.js");
}

const { Writable } = require('stream');

class StoreStream extends Writable {
constructor (options) {
super(options);
this.data = [];
}
_write(chunk, encoding, callback) {
this.data.push(chunk);
callback();
}
}

for (const integrationTest of fs.readdirSync(__dirname + "/integration")) {
// ignore e.g.: `.json` files
if (!/\.(mjs|tsx?|js)$/.test(integrationTest)) continue;

// disabled pending https://github.com/zeit/ncc/issues/141
if (integrationTest.endsWith('loopback.js')) continue;

it(`should execute "ncc run ${integrationTest}"`, async () => {
let expectedStdout;
try {
expectedStdout = fs.readFileSync(`${__dirname}/integration/${integrationTest}.stdout`).toString();
}
catch (e) {}
if (global.gc) global.gc();
const stdout = new StoreStream();
const stderr = new StoreStream();
try {
await nccRun(["run", "--no-cache", "--no-asset-builds", `${__dirname}/integration/${integrationTest}`], stdout, stderr);
}
catch (e) {
if (e.silent) {
let lastErr = stderr.data[stderr.data.length - 1];
if (lastErr)
throw new Error(lastErr);
else
throw new Error('Process exited with code ' + e.exitCode);
}
throw e;
}
if (expectedStdout) {
let stdoutStr = '';
for (const chunk of stdout.data)
stdoutStr += chunk.toString();
expect(stdoutStr.startsWith(expectedStdout));
}
});
}

it(`should execute "ncc build web-vitals" with target config`, async () => {
if (global.gc) global.gc();
const stdout = new StoreStream();
const stderr = new StoreStream();

const tmpOut = path.join(os.tmpdir(), `ncc_${Math.random()}`)

try {
await nccRun(["build", "-o", tmpOut, "--target", "es5", require.resolve('web-vitals/dist/web-vitals.es5.min.js')], stdout, stderr);
}
catch (e) {
if (e.silent) {
let lastErr = stderr.data[stderr.data.length - 1];
if (lastErr)
throw new Error(lastErr);
else
throw new Error('Process exited with code ' + e.exitCode);
}
throw e;
}

const outFile = path.join(tmpOut, 'index.js')
const output = fs.readFileSync(outFile, 'utf8')

// cleanup tmp output
fs.unlinkSync(outFile)
fs.rmdirSync(tmpOut)

expect(output).toContain('function')
// make sure es6 wrapper wasn't used
expect(output).not.toContain('=>')

await new Promise(resolve => setTimeout(resolve, 5000));
});

afterAll(() => {
if (coverage)
process.exit(0);
});

// remove me when node.js makes this the default behavior
process.on("unhandledRejection", e => {
throw e;
});

0 comments on commit 2ba1c22

Please sign in to comment.