@@ -4,7 +4,7 @@ const { nodeFileTrace } = require('../out/node-file-trace');
4
4
5
5
global . _unit = true ;
6
6
7
- const skipOnWindows = [ 'yarn-workspaces' , 'yarn-workspaces-base-root' , 'yarn-workspace-esm' , 'asset-symlink' , 'require-symlink' ] ;
7
+ const skipOnWindows = [ 'yarn-workspaces' , 'yarn-workspaces-base-root' , 'yarn-workspace-esm' , 'asset-symlink' , 'require-symlink' , "cjs-querystring" ] ;
8
8
const unitTestDirs = fs . readdirSync ( join ( __dirname , 'unit' ) ) ;
9
9
const unitTests = [
10
10
...unitTestDirs . map ( testName => ( { testName, isRoot : false } ) ) ,
@@ -13,11 +13,26 @@ const unitTests = [
13
13
14
14
for ( const { testName, isRoot } of unitTests ) {
15
15
const testSuffix = `${ testName } from ${ isRoot ? 'root' : 'cwd' } ` ;
16
- if ( process . platform === 'win32' && ( isRoot || skipOnWindows . includes ( testName ) ) ) {
17
- console . log ( `Skipping unit test on Windows: ${ testSuffix } ` ) ;
18
- continue ;
19
- } ;
20
16
const unitPath = join ( __dirname , 'unit' , testName ) ;
17
+
18
+ if ( process . platform === 'win32' ) {
19
+ if ( isRoot || skipOnWindows . includes ( testName ) ) {
20
+ console . log ( `Skipping unit test on Windows: ${ testSuffix } ` ) ;
21
+ continue ;
22
+ }
23
+ }
24
+ else {
25
+ // The point of this test is to see how filenames with question marks in
26
+ // them are handled, but that's disallowed in Windows, so much so that you
27
+ // can't even check out the commit for CI purposes if the `?`s are
28
+ // permanently in the filename. So we store the file without them and add
29
+ // them in just for the test on non-Windows platforms.
30
+ if ( testName === 'cjs-querystring' ) {
31
+ const currentFilepath = join ( unitPath , "whowhatidk.js" )
32
+ const newFilepath = currentFilepath . replace ( "whowhatidk.js" , "who?what?idk!.js" )
33
+ fs . renameSync ( currentFilepath , newFilepath )
34
+ }
35
+ }
21
36
22
37
it ( `should correctly trace ${ testSuffix } ` , async ( ) => {
23
38
@@ -41,6 +56,25 @@ for (const { testName, isRoot } of unitTests) {
41
56
return null
42
57
}
43
58
}
59
+
60
+ // mock an in-memory module store (such as webpack's) where the same filename with
61
+ // two different querystrings can correspond to two different modules, one importing
62
+ // the other
63
+ if ( testName === "querystring-self-import" ) {
64
+ if ( id . endsWith ( "input.js" ) || id . endsWith ( "base.js" ) || id . endsWith ( "dep.js" ) ) {
65
+ return fs . readFileSync ( id ) . toString ( )
66
+ }
67
+
68
+ if ( id . endsWith ( "base.js?__withQuery" ) ) {
69
+ return `
70
+ import * as origBase from './base';
71
+ export const dogs = origBase.dogs.concat('Cory', 'Bodhi');
72
+ export const cats = origBase.cats.concat('Teaberry', 'Sassafras', 'Persephone');
73
+ export const rats = origBase.rats;
74
+ ` ;
75
+ }
76
+ }
77
+
44
78
return this . constructor . prototype . readFile . apply ( this , arguments ) ;
45
79
} ) ;
46
80
0 commit comments