-
-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(custom-webpack): register ts-node only once (#1035)
* test(custom-webpack): add failing test for #1031 * fix(custom-webpack): actual fix for #1031 Closes #1031
- Loading branch information
Gerkin
authored
Sep 7, 2021
1 parent
64e5e27
commit 359a4c4
Showing
2 changed files
with
68 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
jest.mock('ts-node', () => ({ | ||
register: jest.fn(), | ||
})); | ||
jest.mock('tsconfig-paths', () => ({ | ||
loadConfig: jest.fn().mockReturnValue({}), | ||
})); | ||
import * as utils from './utils'; | ||
jest.spyOn(utils, 'tsNodeRegister'); | ||
|
||
import { getTransforms } from './transform-factories'; | ||
|
||
describe('getTransforms', () => { | ||
beforeEach(() => { | ||
jest.resetModules(); | ||
}); | ||
it('should call ts-node register once with typescript index-html-transform & custom-webpack-config', () => { | ||
jest.mock('test/index-transform.test.ts', () => jest.fn(), { virtual: true }); | ||
jest.mock('test/webpack.test.config.ts', () => jest.fn(), { virtual: true }); | ||
const tsNode = require('ts-node') as jest.Mocked<typeof import('ts-node')>; | ||
|
||
const transforms = getTransforms( | ||
{ | ||
customWebpackConfig: { | ||
path: 'webpack.test.config.ts', | ||
}, | ||
indexTransform: 'index-transform.test.ts', | ||
tsConfig: 'tsconfig.test.json', | ||
}, | ||
{ workspaceRoot: './test' } as any | ||
); | ||
transforms.webpackConfiguration({}); | ||
|
||
expect(utils.tsNodeRegister).toHaveBeenCalledWith( | ||
'test/webpack.test.config.ts', | ||
'test/tsconfig.test.json' | ||
); | ||
expect(utils.tsNodeRegister).toHaveBeenCalledWith( | ||
'index-transform.test.ts', | ||
'test/tsconfig.test.json' | ||
); | ||
expect(tsNode.register).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters