MCPcopy
hub / github.com/jestjs/jest / defineTests

Function defineTests

packages/babel-jest/src/__tests__/index.ts:75–279  ·  view source on GitHub ↗
({
  getBabel,
}: {
  getBabel: () => typeof import('@babel-8/core');
})

Source from the content-addressed store, hash-verified

73});
74
75function 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 );

Callers 1

index.tsFile · 0.70

Calls 15

makeProjectConfigFunction · 0.90
createTransformerFunction · 0.90
expectFunction · 0.85
mockImplementationMethod · 0.80
toBeMethod · 0.80
toBeDefinedMethod · 0.80
toMatchMethod · 0.80
toEqualMethod · 0.80
toBeTruthyMethod · 0.80
toHaveBeenCalledTimesMethod · 0.80
toHaveBeenCalledWithMethod · 0.80
objectContainingMethod · 0.80

Tested by

no test coverage detected