Skip to content

Commit 67bbfeb

Browse files
targosBethGriggs
authored andcommittedSep 21, 2021
test: make tests pass on Windows with Unix EOL
It is possible on Windows to configure Git to checkout line-endings "as-is", which for Node.js means Unix-style. This change makes the tests that rely on line endings pass in that case. PR-URL: #40002 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 73aa4e3 commit 67bbfeb

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed
 

‎test/common/index.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -878,8 +878,14 @@ const common = {
878878
throw new Error('common.PORT cannot be used in a parallelized test');
879879
}
880880
return +process.env.NODE_COMMON_PORT || 12346;
881-
}
881+
},
882882

883+
/**
884+
* Returns the EOL character used by this Git checkout.
885+
*/
886+
get checkoutEOL() {
887+
return fs.readFileSync(__filename).includes('\r\n') ? '\r\n' : '\n';
888+
},
883889
};
884890

885891
const validProperties = new Set(Object.keys(common));

‎test/es-module/test-esm-invalid-pjson.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const { mustCall, isWindows } = require('../common');
3+
const { mustCall, checkoutEOL } = require('../common');
44
const fixtures = require('../common/fixtures');
55
const { spawn } = require('child_process');
66
const { strictEqual, ok } = require('assert');
@@ -21,7 +21,7 @@ child.on('close', mustCall((code, signal) => {
2121
stderr.includes(
2222
`[ERR_INVALID_PACKAGE_CONFIG]: Invalid package config ${invalidJson} ` +
2323
`while importing "invalid-pjson" from ${entry}. ` +
24-
`Unexpected token } in JSON at position ${isWindows ? 16 : 14}`
24+
`Unexpected token } in JSON at position ${12 + checkoutEOL.length * 2}`
2525
),
2626
stderr);
2727
}));

‎test/parallel/test-source-map-enable.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ function nextdir() {
250250
'istanbul-throw.js',
251251
coverageDirectory
252252
);
253-
if (common.isWindows) {
253+
if (common.checkoutEOL === '\r\n') {
254254
assert.deepStrictEqual(sourceMap.lineLengths, [1086, 31, 185, 649, 0]);
255255
} else {
256256
assert.deepStrictEqual(sourceMap.lineLengths, [1085, 30, 184, 648, 0]);

‎test/wasi/test-wasi.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ if (process.argv[2] === 'wasi-child') {
3434
} else {
3535
const assert = require('assert');
3636
const cp = require('child_process');
37-
const { EOL } = require('os');
37+
const { checkoutEOL } = common;
3838

3939
function runWASI(options) {
4040
console.log('executing', options.test);
@@ -69,7 +69,7 @@ if (process.argv[2] === 'wasi-child') {
6969
}
7070
runWASI({ test: 'exitcode', exitCode: 120 });
7171
runWASI({ test: 'fd_prestat_get_refresh' });
72-
runWASI({ test: 'freopen', stdout: `hello from input2.txt${EOL}` });
72+
runWASI({ test: 'freopen', stdout: `hello from input2.txt${checkoutEOL}` });
7373
runWASI({ test: 'ftruncate' });
7474
runWASI({ test: 'getentropy' });
7575

@@ -87,10 +87,10 @@ if (process.argv[2] === 'wasi-child') {
8787
runWASI({ test: 'readdir' });
8888
}
8989

90-
runWASI({ test: 'read_file', stdout: `hello from input.txt${EOL}` });
90+
runWASI({ test: 'read_file', stdout: `hello from input.txt${checkoutEOL}` });
9191
runWASI({
9292
test: 'read_file_twice',
93-
stdout: `hello from input.txt${EOL}hello from input.txt${EOL}`
93+
stdout: `hello from input.txt${checkoutEOL}hello from input.txt${checkoutEOL}`
9494
});
9595
runWASI({ test: 'stat' });
9696
runWASI({ test: 'write_file' });

0 commit comments

Comments
 (0)
Please sign in to comment.