1
1
import { readFixture } from './sandbox/Fixture' ;
2
2
import { join } from 'path' ;
3
+ import os from 'os' ;
3
4
import { createSandbox , Sandbox } from './sandbox/Sandbox' ;
4
5
import {
5
6
createWebpackDevServerDriver ,
@@ -28,7 +29,7 @@ describe('TypeScript Context Option', () => {
28
29
{ async : false , typescript : '~3.0.0' } ,
29
30
{ async : true , typescript : '~3.6.0' } ,
30
31
{ async : false , typescript : '~3.8.0' } ,
31
- ] ) ( 'uses context to resolve project files for %p' , async ( { async, typescript } ) => {
32
+ ] ) ( 'uses context and cwd to resolve project files for %p' , async ( { async, typescript } ) => {
32
33
await sandbox . load ( [
33
34
await readFixture ( join ( __dirname , 'fixtures/environment/typescript-basic.fixture' ) , {
34
35
FORK_TS_CHECKER_WEBPACK_PLUGIN_VERSION : JSON . stringify (
@@ -65,13 +66,18 @@ describe('TypeScript Context Option', () => {
65
66
exclude : [ 'node_modules' ] ,
66
67
} )
67
68
) ;
69
+ await sandbox . patch (
70
+ 'webpack.config.js' ,
71
+ "entry: './src/index.ts'," ,
72
+ "entry: path.resolve(__dirname, './src/index.ts'),"
73
+ ) ;
68
74
await sandbox . patch (
69
75
'webpack.config.js' ,
70
76
' logger: {' ,
71
77
[
72
78
' typescript: {' ,
73
79
' enabled: true,' ,
74
- ' configFile: "build/tsconfig.json",' ,
80
+ ' configFile: path.resolve(__dirname, "build/tsconfig.json") ,' ,
75
81
' context: __dirname,' ,
76
82
' },' ,
77
83
' logger: {' ,
@@ -82,12 +88,21 @@ describe('TypeScript Context Option', () => {
82
88
' transpileOnly: true' ,
83
89
[
84
90
' transpileOnly: true,' ,
85
- ' configFile: "build/tsconfig.json",' ,
91
+ ' configFile: path.resolve(__dirname, "build/tsconfig.json") ,' ,
86
92
' context: __dirname,' ,
87
93
] . join ( '\n' )
88
94
) ;
95
+ // create additional directory for cwd test
96
+ await sandbox . write ( 'foo/.gitignore' , '' ) ;
89
97
90
- const driver = createWebpackDevServerDriver ( sandbox . spawn ( 'npm run webpack-dev-server' ) , async ) ;
98
+ const driver = createWebpackDevServerDriver (
99
+ sandbox . spawn (
100
+ `../node_modules/.bin/webpack-dev-server${ os . platform ( ) === 'win32' ? '.cmd' : '' } ` ,
101
+ { } ,
102
+ join ( sandbox . context , 'foo' )
103
+ ) ,
104
+ async
105
+ ) ;
91
106
92
107
// first compilation is successful
93
108
await driver . waitForNoErrors ( ) ;
@@ -103,7 +118,7 @@ describe('TypeScript Context Option', () => {
103
118
const errors = await driver . waitForErrors ( ) ;
104
119
expect ( errors ) . toEqual ( [
105
120
[
106
- 'ERROR in src/model/User.ts:11:16' ,
121
+ 'ERROR in ../ src/model/User.ts:11:16' ,
107
122
"TS2339: Property 'firstName' does not exist on type 'User'." ,
108
123
' 9 | ' ,
109
124
' 10 | function getUserName(user: User): string {' ,
@@ -114,7 +129,7 @@ describe('TypeScript Context Option', () => {
114
129
' 14 | }' ,
115
130
] . join ( '\n' ) ,
116
131
[
117
- 'ERROR in src/model/User.ts:11:32' ,
132
+ 'ERROR in ../ src/model/User.ts:11:32' ,
118
133
"TS2339: Property 'lastName' does not exist on type 'User'." ,
119
134
' 9 | ' ,
120
135
' 10 | function getUserName(user: User): string {' ,
0 commit comments