/
ts_config.test.ts
42 lines (34 loc) · 1.08 KB
/
ts_config.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import getTsLoaderOptions from '../ts_config';
// eslint-disable-next-line global-require, jest/no-mocks-import
jest.mock('fs', () => require('../../../../../__mocks__/fs'));
jest.mock('path', () => ({
resolve: () => 'tsconfig.json',
}));
jest.mock('@storybook/node-logger');
const setupFiles = (files: any) => {
// eslint-disable-next-line no-underscore-dangle, global-require
require('fs').__setMockFiles(files);
};
describe('ts_config', () => {
it('should return the config with the path to the tsconfig.json', () => {
setupFiles({ 'tsconfig.json': '{}' });
const config = getTsLoaderOptions('.foo');
expect(config).toEqual({
transpileOnly: true,
compilerOptions: {
emitDecoratorMetadata: true,
},
configFile: 'tsconfig.json',
});
});
it('should return object with transpileOnly: true when there is no tsconfig.json', () => {
setupFiles({});
const config = getTsLoaderOptions('.foo');
expect(config).toEqual({
transpileOnly: true,
compilerOptions: {
emitDecoratorMetadata: true,
},
});
});
});