({
getBabel,
}: {
getBabel: () => typeof import('@babel-8/core');
})
| 73 | }); |
| 74 | |
| 75 | function defineTests({ |
| 76 | getBabel, |
| 77 | }: { |
| 78 | getBabel: () => typeof import('@babel-8/core'); |
| 79 | }) { |
| 80 | let babel: typeof import('@babel-8/core'); |
| 81 | beforeAll(() => { |
| 82 | babel = getBabel(); |
| 83 | }); |
| 84 | |
| 85 | beforeEach(() => { |
| 86 | jest.clearAllMocks(); |
| 87 | |
| 88 | mockedBabel.transformSync.mockImplementation(babel.transformSync); |
| 89 | mockedBabel.transformAsync.mockImplementation(babel.transformAsync); |
| 90 | mockedBabel.loadPartialConfigSync.mockImplementation( |
| 91 | babel.loadPartialConfigSync, |
| 92 | ); |
| 93 | mockedBabel.loadPartialConfigAsync.mockImplementation( |
| 94 | babel.loadPartialConfigAsync, |
| 95 | ); |
| 96 | }); |
| 97 | test('Returns source string with inline maps when no transformOptions is passed', () => { |
| 98 | const result = defaultBabelJestTransformer.process( |
| 99 | sourceString, |
| 100 | 'dummy_path.js', |
| 101 | { |
| 102 | cacheFS: new Map<string, string>(), |
| 103 | config: makeProjectConfig(), |
| 104 | configString: JSON.stringify(makeProjectConfig()), |
| 105 | instrument: false, |
| 106 | transformerConfig: {}, |
| 107 | } as TransformOptions<BabelTransformOptions>, |
| 108 | ); |
| 109 | |
| 110 | expect(typeof result).toBe('object'); |
| 111 | expect(result.code).toBeDefined(); |
| 112 | expect(result.map).toBeDefined(); |
| 113 | expect(result.code).toMatch('//# sourceMappingURL'); |
| 114 | expect(result.code).toMatch('customMultiply'); |
| 115 | expect((result as BabelFileResult).map!.sources).toEqual(['dummy_path.js']); |
| 116 | expect( |
| 117 | JSON.stringify((result as BabelFileResult).map!.sourcesContent), |
| 118 | ).toMatch('customMultiply'); |
| 119 | }); |
| 120 | |
| 121 | test('Returns source string with inline maps when no transformOptions is passed async', async () => { |
| 122 | const result = await defaultBabelJestTransformer.processAsync!( |
| 123 | sourceString, |
| 124 | 'dummy_path.js', |
| 125 | { |
| 126 | cacheFS: new Map<string, string>(), |
| 127 | config: makeProjectConfig(), |
| 128 | configString: JSON.stringify(makeProjectConfig()), |
| 129 | instrument: false, |
| 130 | transformerConfig: {}, |
| 131 | } as TransformOptions<BabelTransformOptions>, |
| 132 | ); |
no test coverage detected