Skip to content

Commit 09234d1

Browse files
Maybe _this_ makes the tests pass?
1 parent acfae6b commit 09234d1

File tree

3 files changed

+442
-431
lines changed

3 files changed

+442
-431
lines changed

packages/babel-jest/src/__tests__/getCacheKey.test.ts

Lines changed: 169 additions & 173 deletions
Original file line numberDiff line numberDiff line change
@@ -43,211 +43,207 @@ afterEach(() => {
4343
}
4444
});
4545

46-
const babelVersions = [
47-
{babel: require('@babel/core'), version: '7'},
48-
{
49-
babel:
50-
Number.parseInt(process.versions.node, 10) >= 20 &&
51-
originalNodeRequire('@babel-8/core'),
52-
version: '8',
53-
},
54-
];
55-
56-
describe.skip.each(babelVersions.filter(x => !x.babel))(
57-
'babel $version',
58-
() => {},
59-
);
60-
describe.each(babelVersions.filter(x => x.babel))(
61-
'babel $version',
62-
({babel}) => {
63-
describe('getCacheKey', () => {
64-
const sourceText = 'mock source';
65-
const sourcePath = 'mock-source-path.js';
66-
67-
const transformOptions = {
68-
config: {rootDir: 'mock-root-dir'},
69-
configString: 'mock-config-string',
70-
instrument: true,
71-
} as TransformOptions<BabelTransformOptions>;
72-
73-
const oldCacheKey = getCacheKey!(
46+
describe('babel 7', () => {
47+
defineTests({babel: require('@babel/core')});
48+
});
49+
50+
if (Number.parseInt(process.versions.node, 10) >= 20) {
51+
describe('babel 8', () => {
52+
defineTests({
53+
babel: originalNodeRequire('@babel-8/core'),
54+
});
55+
});
56+
} else {
57+
// eslint-disable-next-line jest/no-identical-title
58+
describe('babel 8', () => {
59+
defineTests({babel: null as unknown as typeof import('@babel-8/core')});
60+
});
61+
}
62+
63+
function defineTests({babel}: {babel: typeof import('@babel-8/core')}) {
64+
describe('getCacheKey', () => {
65+
const sourceText = 'mock source';
66+
const sourcePath = 'mock-source-path.js';
67+
68+
const transformOptions = {
69+
config: {rootDir: 'mock-root-dir'},
70+
configString: 'mock-config-string',
71+
instrument: true,
72+
} as TransformOptions<BabelTransformOptions>;
73+
74+
const oldCacheKey = getCacheKey!(sourceText, sourcePath, transformOptions);
75+
76+
test('returns cache key hash', () => {
77+
expect(oldCacheKey).toHaveLength(32);
78+
});
79+
80+
test('if `THIS_FILE` value is changing', async () => {
81+
jest.doMock('graceful-fs', () => ({
82+
readFileSync: () => 'new this file',
83+
}));
84+
85+
const {createTransformer} =
86+
require('../index') as typeof import('../index');
87+
88+
const newCacheKey = (await createTransformer()).getCacheKey!(
7489
sourceText,
7590
sourcePath,
7691
transformOptions,
7792
);
7893

79-
test('returns cache key hash', () => {
80-
expect(oldCacheKey).toHaveLength(32);
94+
expect(oldCacheKey).not.toEqual(newCacheKey);
95+
});
96+
97+
test('if `babelOptions.options` value is changing', async () => {
98+
jest.doMock('../babel', () => {
99+
return {
100+
...babel,
101+
loadPartialConfigSync: (
102+
options: Parameters<typeof babel.loadPartialConfigSync>[0],
103+
) => ({
104+
...babel.loadPartialConfigSync(options),
105+
options: 'new-options',
106+
}),
107+
};
81108
});
82109

83-
test('if `THIS_FILE` value is changing', async () => {
84-
jest.doMock('graceful-fs', () => ({
85-
readFileSync: () => 'new this file',
86-
}));
110+
const {createTransformer} =
111+
require('../index') as typeof import('../index');
87112

88-
const {createTransformer} =
89-
require('../index') as typeof import('../index');
113+
const newCacheKey = (await createTransformer()).getCacheKey!(
114+
sourceText,
115+
sourcePath,
116+
transformOptions,
117+
);
90118

91-
const newCacheKey = (await createTransformer()).getCacheKey!(
92-
sourceText,
93-
sourcePath,
94-
transformOptions,
95-
);
119+
expect(oldCacheKey).not.toEqual(newCacheKey);
120+
});
96121

97-
expect(oldCacheKey).not.toEqual(newCacheKey);
98-
});
122+
test('if `sourceText` value is changing', () => {
123+
const newCacheKey = getCacheKey!(
124+
'new source text',
125+
sourcePath,
126+
transformOptions,
127+
);
99128

100-
test('if `babelOptions.options` value is changing', async () => {
101-
jest.doMock('../babel', () => {
102-
return {
103-
...babel,
104-
loadPartialConfigSync: (
105-
options: Parameters<typeof babel.loadPartialConfigSync>[0],
106-
) => ({
107-
...babel.loadPartialConfigSync(options),
108-
options: 'new-options',
109-
}),
110-
};
111-
});
112-
113-
const {createTransformer} =
114-
require('../index') as typeof import('../index');
115-
116-
const newCacheKey = (await createTransformer()).getCacheKey!(
117-
sourceText,
118-
sourcePath,
119-
transformOptions,
120-
);
121-
122-
expect(oldCacheKey).not.toEqual(newCacheKey);
123-
});
129+
expect(oldCacheKey).not.toEqual(newCacheKey);
130+
});
124131

125-
test('if `sourceText` value is changing', () => {
126-
const newCacheKey = getCacheKey!(
127-
'new source text',
128-
sourcePath,
129-
transformOptions,
130-
);
132+
test('if `sourcePath` value is changing', () => {
133+
const newCacheKey = getCacheKey!(
134+
sourceText,
135+
'new-source-path.js',
136+
transformOptions,
137+
);
131138

132-
expect(oldCacheKey).not.toEqual(newCacheKey);
139+
expect(oldCacheKey).not.toEqual(newCacheKey);
140+
});
141+
142+
test('if `configString` value is changing', () => {
143+
const newCacheKey = getCacheKey!(sourceText, sourcePath, {
144+
...transformOptions,
145+
configString: 'new-config-string',
133146
});
134147

135-
test('if `sourcePath` value is changing', () => {
136-
const newCacheKey = getCacheKey!(
137-
sourceText,
138-
'new-source-path.js',
139-
transformOptions,
140-
);
148+
expect(oldCacheKey).not.toEqual(newCacheKey);
149+
});
141150

142-
expect(oldCacheKey).not.toEqual(newCacheKey);
151+
test('if `babelOptions.config` value is changing', async () => {
152+
jest.doMock('../babel', () => {
153+
return {
154+
...babel,
155+
loadPartialConfigSync: (
156+
options: Parameters<typeof babel.loadPartialConfigSync>[0],
157+
) => ({
158+
...babel.loadPartialConfigSync(options),
159+
config: 'new-config',
160+
}),
161+
};
143162
});
144163

145-
test('if `configString` value is changing', () => {
146-
const newCacheKey = getCacheKey!(sourceText, sourcePath, {
147-
...transformOptions,
148-
configString: 'new-config-string',
149-
});
164+
const {createTransformer} =
165+
require('../index') as typeof import('../index');
150166

151-
expect(oldCacheKey).not.toEqual(newCacheKey);
152-
});
167+
const newCacheKey = (await createTransformer()).getCacheKey!(
168+
sourceText,
169+
sourcePath,
170+
transformOptions,
171+
);
153172

154-
test('if `babelOptions.config` value is changing', async () => {
155-
jest.doMock('../babel', () => {
156-
return {
157-
...babel,
158-
loadPartialConfigSync: (
159-
options: Parameters<typeof babel.loadPartialConfigSync>[0],
160-
) => ({
161-
...babel.loadPartialConfigSync(options),
162-
config: 'new-config',
163-
}),
164-
};
165-
});
166-
167-
const {createTransformer} =
168-
require('../index') as typeof import('../index');
169-
170-
const newCacheKey = (await createTransformer()).getCacheKey!(
171-
sourceText,
172-
sourcePath,
173-
transformOptions,
174-
);
175-
176-
expect(oldCacheKey).not.toEqual(newCacheKey);
177-
});
173+
expect(oldCacheKey).not.toEqual(newCacheKey);
174+
});
178175

179-
test('if `babelOptions.babelrc` value is changing', async () => {
180-
jest.doMock('../babel', () => {
181-
return {
182-
...babel,
183-
loadPartialConfig: (
184-
options: Parameters<typeof babel.loadPartialConfig>[0],
185-
) => ({
186-
...babel.loadPartialConfig(options),
187-
babelrc: 'new-babelrc',
188-
}),
189-
};
190-
});
191-
192-
const {createTransformer} =
193-
require('../index') as typeof import('../index');
194-
195-
const newCacheKey = (await createTransformer()).getCacheKey!(
196-
sourceText,
197-
sourcePath,
198-
transformOptions,
199-
);
200-
201-
expect(oldCacheKey).not.toEqual(newCacheKey);
176+
test('if `babelOptions.babelrc` value is changing', async () => {
177+
jest.doMock('../babel', () => {
178+
return {
179+
...babel,
180+
loadPartialConfig: (
181+
options: Parameters<typeof babel.loadPartialConfig>[0],
182+
) => ({
183+
...babel.loadPartialConfig(options),
184+
babelrc: 'new-babelrc',
185+
}),
186+
};
202187
});
203188

204-
test('if `instrument` value is changing', () => {
205-
const newCacheKey = getCacheKey!(sourceText, sourcePath, {
206-
...transformOptions,
207-
instrument: false,
208-
});
189+
const {createTransformer} =
190+
require('../index') as typeof import('../index');
191+
192+
const newCacheKey = (await createTransformer()).getCacheKey!(
193+
sourceText,
194+
sourcePath,
195+
transformOptions,
196+
);
209197

210-
expect(oldCacheKey).not.toEqual(newCacheKey);
198+
expect(oldCacheKey).not.toEqual(newCacheKey);
199+
});
200+
201+
test('if `instrument` value is changing', () => {
202+
const newCacheKey = getCacheKey!(sourceText, sourcePath, {
203+
...transformOptions,
204+
instrument: false,
211205
});
212206

213-
test('if `process.env.NODE_ENV` value is changing', () => {
214-
process.env.NODE_ENV = 'NEW_NODE_ENV';
207+
expect(oldCacheKey).not.toEqual(newCacheKey);
208+
});
215209

216-
const newCacheKey = getCacheKey!(
217-
sourceText,
218-
sourcePath,
219-
transformOptions,
220-
);
210+
test('if `process.env.NODE_ENV` value is changing', () => {
211+
process.env.NODE_ENV = 'NEW_NODE_ENV';
221212

222-
expect(oldCacheKey).not.toEqual(newCacheKey);
223-
});
213+
const newCacheKey = getCacheKey!(
214+
sourceText,
215+
sourcePath,
216+
transformOptions,
217+
);
224218

225-
test('if `process.env.BABEL_ENV` value is changing', () => {
226-
process.env.BABEL_ENV = 'NEW_BABEL_ENV';
219+
expect(oldCacheKey).not.toEqual(newCacheKey);
220+
});
227221

228-
const newCacheKey = getCacheKey!(
229-
sourceText,
230-
sourcePath,
231-
transformOptions,
232-
);
222+
test('if `process.env.BABEL_ENV` value is changing', () => {
223+
process.env.BABEL_ENV = 'NEW_BABEL_ENV';
233224

234-
expect(oldCacheKey).not.toEqual(newCacheKey);
235-
});
225+
const newCacheKey = getCacheKey!(
226+
sourceText,
227+
sourcePath,
228+
transformOptions,
229+
);
236230

237-
test('if node version is changing', () => {
238-
// @ts-expect-error: Testing purpose
239-
delete process.version;
240-
// @ts-expect-error: Testing purpose
241-
process.version = 'new-node-version';
231+
expect(oldCacheKey).not.toEqual(newCacheKey);
232+
});
242233

243-
const newCacheKey = getCacheKey!(
244-
sourceText,
245-
sourcePath,
246-
transformOptions,
247-
);
234+
test('if node version is changing', () => {
235+
// @ts-expect-error: Testing purpose
236+
delete process.version;
237+
// @ts-expect-error: Testing purpose
238+
process.version = 'new-node-version';
248239

249-
expect(oldCacheKey).not.toEqual(newCacheKey);
250-
});
240+
const newCacheKey = getCacheKey!(
241+
sourceText,
242+
sourcePath,
243+
transformOptions,
244+
);
245+
246+
expect(oldCacheKey).not.toEqual(newCacheKey);
251247
});
252-
},
253-
);
248+
});
249+
}

0 commit comments

Comments
 (0)