Skip to content

Commit 4c5fe12

Browse files
authored
chore: add windows to CI (#896)
* chore: add windows to CI * Use path.join() * Use jest.js * Normalize for windows * Repalce \r * Ignore some tests on windows * Update `testMatch` * Update cli tests * Add logs * Use `path.join()`
1 parent 326cdf3 commit 4c5fe12

9 files changed

Lines changed: 726 additions & 469 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
strategy:
1515
fail-fast: false
1616
matrix:
17-
os: [ubuntu-latest, macos-latest]
17+
os: [ubuntu-latest, macos-latest, windows-latest]
1818
node: [14, 16]
1919
runs-on: ${{ matrix.os }}
2020
steps:

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ module.exports = {
22
collectCoverageFrom: ["src/**/*.js"],
33
coverageReporters: ["html", "lcov"],
44
testEnvironment: "node",
5-
testMatch: ["<rootDir>/test/?(*.)+(spec|test).js?(x)"]
5+
testMatch: ["<rootDir>/test/**/*.test.js"]
66
};

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
"build": "node scripts/build.js",
1616
"build-test-binary": "cd test/binary && node-gyp rebuild && cp build/Release/hello.node ../integration/hello.node",
1717
"codecov": "codecov",
18-
"test": "node --expose-gc --max_old_space_size=4096 node_modules/.bin/jest",
19-
"test-coverage": "node --expose-gc --max_old_space_size=4096 node_modules/.bin/jest --coverage --globals \"{\\\"coverage\\\":true}\" && codecov",
18+
"test": "node --expose-gc --max_old_space_size=4096 node_modules/jest/bin/jest.js",
19+
"test-coverage": "node --expose-gc --max_old_space_size=4096 node_modules/jest/bin/jest.js --coverage --globals \"{\\\"coverage\\\":true}\" && codecov",
2020
"prepublishOnly": "node scripts/build.js --no-cache"
2121
},
2222
"devDependencies": {
@@ -60,7 +60,7 @@
6060
"hot-shots": "^8.5.0",
6161
"ioredis": "^4.2.0",
6262
"isomorphic-unfetch": "^3.0.0",
63-
"jest": "^27.4.5",
63+
"jest": "^27.5.1",
6464
"jimp": "^0.16.1",
6565
"jugglingdb": "2.0.1",
6666
"koa": "^2.6.2",

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ function ncc (
545545
if (map && sourceMapRegister) {
546546
const registerExt = esm ? '.cjs' : ext;
547547
code = (esm ? `import './sourcemap-register${registerExt}';` : `require('./sourcemap-register${registerExt}');`) + code;
548-
assets[`sourcemap-register${registerExt}`] = { source: fs.readFileSync(`${__dirname}/sourcemap-register.js.cache.js`), permissions: defaultPermissions };
548+
assets[`sourcemap-register${registerExt}`] = { source: fs.readFileSync(join(__dirname, `sourcemap-register.js.cache.js`)), permissions: defaultPermissions };
549549
}
550550

551551
if (esm && !filename.endsWith('.mjs')) {

test/cli.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
[
1+
const { join } = require('path')
2+
3+
module.exports = [
24
{
35
args: ["run", "test/fixtures/ts-interop/interop.ts"],
46
expect: { code: 0 }
@@ -18,7 +20,7 @@
1820
{
1921
args: ["build", "test/integration/test.ts", "-o", "tmp"],
2022
expect (code, stdout, stderr) {
21-
return stdout.toString().indexOf('tmp/index.js') !== -1;
23+
return stdout.toString().indexOf(join('tmp', 'index.js')) !== -1;
2224
}
2325
},
2426
{
@@ -71,21 +73,21 @@
7173
{
7274
args: ["build", "-o", "tmp", "test/fixtures/test.cjs"],
7375
expect (code, stdout, stderr) {
74-
return stdout.toString().indexOf('tmp/index.cjs') !== -1;
76+
return stdout.toString().indexOf(join('tmp', 'index.cjs')) !== -1;
7577
}
7678
},
7779
{
7880
args: ["build", "-o", "tmp", "test/fixtures/test.mjs"],
7981
expect (code, stdout, stderr) {
80-
return stdout.toString().indexOf('tmp/index.mjs') !== -1;
82+
return stdout.toString().indexOf(join('tmp', 'index.mjs')) !== -1;
8183
}
8284
},
8385
{
8486
args: ["build", "-o", "tmp", "test/fixtures/test.mjs", "--stats-out", "tmp/stats.json"],
8587
expect (code, stdout, stderr) {
8688
const fs = require('fs');
8789
try {
88-
JSON.parse(fs.readFileSync('tmp/stats.json', 'utf8'));
90+
JSON.parse(fs.readFileSync(join('tmp', 'stats.json'), 'utf8'));
8991
} catch {
9092
return false;
9193
}
@@ -112,7 +114,7 @@
112114
args: ["build", "-o", "tmp", "test/fixtures/module.cjs"],
113115
expect (code, stdout) {
114116
const fs = require('fs');
115-
return code === 0 && fs.readFileSync('tmp/index.js', 'utf8').toString().indexOf('export {') === -1;
117+
return code === 0 && fs.readFileSync(join('tmp', 'index.js'), 'utf8').toString().indexOf('export {') === -1;
116118
}
117119
}
118120
]

test/cli.test.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
const fs = require("fs");
21
const { fork } = require("child_process");
3-
const coverage = global.coverage;
2+
const { join } = require("path");
3+
const cliTests = require("./cli.js");
4+
const file = global.coverage ? "/../src/cli.js" : "/../dist/ncc/cli.js";
45

56
jest.setTimeout(20000);
67

7-
for (const cliTest of eval(fs.readFileSync(__dirname + "/cli.js").toString())) {
8+
for (const cliTest of cliTests) {
89
it(`should execute "ncc ${(cliTest.args || []).join(" ")}"`, async () => {
9-
const ps = fork(__dirname + (coverage ? "/../src/cli.js" : "/../dist/ncc/cli.js"), cliTest.args || [], {
10+
const ps = fork(join(__dirname, file), cliTest.args || [], {
1011
stdio: "pipe",
1112
env: { ...process.env, ...cliTest.env },
1213
});

test/integration.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ const coverage = global.coverage;
66
// the twilio test can take a while (large codebase)
77
jest.setTimeout(200000);
88

9+
const skipOnWindows = [
10+
'binary-require.js',
11+
'browserify-middleware.js',
12+
'oracledb.js',
13+
'tensorflow.js',
14+
]
15+
916
let nccRun;
1017
if (coverage) {
1118
nccRun = require(__dirname + "/../src/cli.js");
@@ -34,6 +41,9 @@ for (const integrationTest of fs.readdirSync(__dirname + "/integration")) {
3441
// disabled pending https://github.com/zeit/ncc/issues/141
3542
if (integrationTest.endsWith('loopback.js')) continue;
3643

44+
// ignore a few tests known to fail on windows
45+
if (process.platform === 'win32' && skipOnWindows.includes(integrationTest)) continue;
46+
3747
it(`should execute "ncc run ${integrationTest}"`, async () => {
3848
let expectedStdout;
3949
try {

test/unit.test.js

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,20 @@ const ncc = coverage ? require("../src/index") : require("../");
44

55
jest.setTimeout(20000);
66

7+
function normalizeForWindows(str) {
8+
return str.trim().replace(/\\r/g, '').replace(/\r/g, '').replace(/;+/g, ';');
9+
}
10+
711
for (const unitTest of fs.readdirSync(`${__dirname}/unit`)) {
8-
it(`should generate correct output for ${unitTest}`, async () => {
12+
if (process.platform === 'win32' && unitTest.includes('shebang')) {
13+
continue;
14+
}
15+
it(`should generate correct output for ${unitTest}`, async () => {
916
const testDir = `${__dirname}/unit/${unitTest}`;
10-
const expected = fs
11-
.readFileSync(`${testDir}/output${coverage ? '-coverage' : ''}.js`)
12-
.toString()
13-
.trim()
14-
// Windows support
15-
.replace(/\r/g, "");
17+
const expected = normalizeForWindows(fs.readFileSync(`${testDir}/output${coverage ? '-coverage' : ''}.js`, 'utf8'));
1618
let expectedSourceMap;
1719
try {
18-
expectedSourceMap = fs
19-
.readFileSync(`${testDir}/output${coverage ? '-coverage' : ''}.js.map`)
20-
.toString()
21-
.trim()
22-
// Windows support
23-
.replace(/\r/g, "");
20+
expectedSourceMap = normalizeForWindows(fs.readFileSync(`${testDir}/output${coverage ? '-coverage' : ''}.js.map`, 'utf8'));
2421
} catch (_) {}
2522

2623
let opts;
@@ -59,11 +56,7 @@ for (const unitTest of fs.readdirSync(`${__dirname}/unit`)) {
5956
if (unitTest.includes('minify') && !unitTest.includes('minify-err')) {
6057
expect(assets['index.js.map']).toBeDefined()
6158
}
62-
const actual = code
63-
.trim()
64-
// Windows support
65-
.replace(/\r/g, "")
66-
.replace(/;+/g, ";");
59+
const actual = normalizeForWindows(code);
6760
try {
6861
expect(actual).toBe(expected);
6962
} catch (e) {
@@ -73,10 +66,7 @@ for (const unitTest of fs.readdirSync(`${__dirname}/unit`)) {
7366
}
7467

7568
if (map) {
76-
const actualSourceMap = map
77-
.trim()
78-
// Windows support
79-
.replace(/\r/g, "");
69+
const actualSourceMap = normalizeForWindows(map);
8070
try {
8171
expect(actualSourceMap).toBe(expectedSourceMap);
8272
} catch (e) {

0 commit comments

Comments
 (0)