Skip to content

Commit 67bbfeb

Browse files
targosBethGriggs
authored andcommitted
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

4 files changed

Lines changed: 14 additions & 8 deletions

File tree

‎test/common/index.js‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -878,8 +878,14 @@ const common = {
878878
thrownewError('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+
getcheckoutEOL(){
887+
returnfs.readFileSync(__filename).includes('\r\n') ? '\r\n' : '\n';
888+
},
883889
};
884890

885891
constvalidProperties=newSet(Object.keys(common));

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

Lines changed: 2 additions & 2 deletions
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
constfixtures=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‎

Lines changed: 1 addition & 1 deletion
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‎

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

3939
functionrunWASI(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)