({
getBabel,
}: {
getBabel: () => typeof import('@babel-8/core');
})
| 57 | }); |
| 58 | |
| 59 | function defineTests({ |
| 60 | getBabel, |
| 61 | }: { |
| 62 | getBabel: () => typeof import('@babel-8/core'); |
| 63 | }) { |
| 64 | describe('getCacheKey', () => { |
| 65 | let babel: typeof import('@babel-8/core'); |
| 66 | beforeAll(() => { |
| 67 | babel = getBabel(); |
| 68 | }); |
| 69 | |
| 70 | const sourceText = 'mock source'; |
| 71 | const sourcePath = 'mock-source-path.js'; |
| 72 | |
| 73 | const transformOptions = { |
| 74 | config: {rootDir: 'mock-root-dir'}, |
| 75 | configString: 'mock-config-string', |
| 76 | instrument: true, |
| 77 | } as TransformOptions<BabelTransformOptions>; |
| 78 | |
| 79 | const oldCacheKey = getCacheKey!(sourceText, sourcePath, transformOptions); |
| 80 | |
| 81 | test('returns cache key hash', () => { |
| 82 | expect(oldCacheKey).toHaveLength(32); |
| 83 | }); |
| 84 | |
| 85 | test('if `THIS_FILE` value is changing', async () => { |
| 86 | jest.doMock('graceful-fs', () => ({ |
| 87 | readFileSync: () => 'new this file', |
| 88 | })); |
| 89 | |
| 90 | const {createTransformer} = |
| 91 | require('../index') as typeof import('../index'); |
| 92 | |
| 93 | const newCacheKey = (await createTransformer()).getCacheKey!( |
| 94 | sourceText, |
| 95 | sourcePath, |
| 96 | transformOptions, |
| 97 | ); |
| 98 | |
| 99 | expect(oldCacheKey).not.toEqual(newCacheKey); |
| 100 | }); |
| 101 | |
| 102 | test('if `babelOptions.options` value is changing', async () => { |
| 103 | jest.doMock('../babel', () => { |
| 104 | return { |
| 105 | ...babel, |
| 106 | loadPartialConfigSync: ( |
| 107 | options: Parameters<typeof babel.loadPartialConfigSync>[0], |
| 108 | ) => ({ |
| 109 | ...babel.loadPartialConfigSync(options), |
| 110 | options: 'new-options', |
| 111 | }), |
| 112 | }; |
| 113 | }); |
| 114 | |
| 115 | const {createTransformer} = |
| 116 | require('../index') as typeof import('../index'); |
no test coverage detected