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

Function defineTests

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

Source from the content-addressed store, hash-verified

57});
58
59function 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');

Callers 1

Calls 8

expectFunction · 0.85
toHaveLengthMethod · 0.80
doMockMethod · 0.80
toEqualMethod · 0.80
describeFunction · 0.50
beforeAllFunction · 0.50
testFunction · 0.50
createTransformerFunction · 0.50

Tested by

no test coverage detected