11import { readFixture } from './sandbox/Fixture' ;
22import { join } from 'path' ;
3+ import os from 'os' ;
34import { createSandbox , Sandbox } from './sandbox/Sandbox' ;
45import {
56 createWebpackDevServerDriver ,
@@ -28,7 +29,7 @@ describe('TypeScript Context Option', () => {
2829 { async : false , typescript : '~3.0.0' } ,
2930 { async : true , typescript : '~3.6.0' } ,
3031 { 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 } ) => {
3233 await sandbox . load ( [
3334 await readFixture ( join ( __dirname , 'fixtures/environment/typescript-basic.fixture' ) , {
3435 FORK_TS_CHECKER_WEBPACK_PLUGIN_VERSION : JSON . stringify (
@@ -65,13 +66,18 @@ describe('TypeScript Context Option', () => {
6566 exclude : [ 'node_modules' ] ,
6667 } )
6768 ) ;
69+ await sandbox . patch (
70+ 'webpack.config.js' ,
71+ "entry: './src/index.ts'," ,
72+ "entry: path.resolve(__dirname, './src/index.ts'),"
73+ ) ;
6874 await sandbox . patch (
6975 'webpack.config.js' ,
7076 ' logger: {' ,
7177 [
7278 ' typescript: {' ,
7379 ' enabled: true,' ,
74- ' configFile: "build/tsconfig.json",' ,
80+ ' configFile: path.resolve(__dirname, "build/tsconfig.json") ,' ,
7581 ' context: __dirname,' ,
7682 ' },' ,
7783 ' logger: {' ,
@@ -82,12 +88,21 @@ describe('TypeScript Context Option', () => {
8288 ' transpileOnly: true' ,
8389 [
8490 ' transpileOnly: true,' ,
85- ' configFile: "build/tsconfig.json",' ,
91+ ' configFile: path.resolve(__dirname, "build/tsconfig.json") ,' ,
8692 ' context: __dirname,' ,
8793 ] . join ( '\n' )
8894 ) ;
95+ // create additional directory for cwd test
96+ await sandbox . write ( 'foo/.gitignore' , '' ) ;
8997
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+ ) ;
91106
92107 // first compilation is successful
93108 await driver . waitForNoErrors ( ) ;
@@ -103,7 +118,7 @@ describe('TypeScript Context Option', () => {
103118 const errors = await driver . waitForErrors ( ) ;
104119 expect ( errors ) . toEqual ( [
105120 [
106- 'ERROR in src/model/User.ts:11:16' ,
121+ 'ERROR in ../ src/model/User.ts:11:16' ,
107122 "TS2339: Property 'firstName' does not exist on type 'User'." ,
108123 ' 9 | ' ,
109124 ' 10 | function getUserName(user: User): string {' ,
@@ -114,7 +129,7 @@ describe('TypeScript Context Option', () => {
114129 ' 14 | }' ,
115130 ] . join ( '\n' ) ,
116131 [
117- 'ERROR in src/model/User.ts:11:32' ,
132+ 'ERROR in ../ src/model/User.ts:11:32' ,
118133 "TS2339: Property 'lastName' does not exist on type 'User'." ,
119134 ' 9 | ' ,
120135 ' 10 | function getUserName(user: User): string {' ,
0 commit comments