Skip to content

Commit

Permalink
Update tests to account for babel-jest not having default process/pro…
Browse files Browse the repository at this point in the history
…cessAsync exports
  • Loading branch information
fatso83 committed Feb 17, 2022
1 parent d4ac18f commit 91a8f0e
Showing 1 changed file with 22 additions and 44 deletions.
66 changes: 22 additions & 44 deletions packages/babel-jest/src/__tests__/getCacheKey.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import type {TransformOptions as BabelTransformOptions} from '@babel/core';
import type {TransformOptions as JestTransformOptions} from '@jest/transform';
import babelJest from '../index';

const {getCacheKey} = babelJest.createTransformer();

const processVersion = process.version;
const nodeEnv = process.env.NODE_ENV;
const babelEnv = process.env.BABEL_ENV;
Expand Down Expand Up @@ -39,11 +41,7 @@ describe('getCacheKey', () => {
instrument: true,
} as JestTransformOptions;

const oldCacheKey = babelJest.getCacheKey(
sourceText,
sourcePath,
transformOptions,
);
const oldCacheKey = getCacheKey(sourceText, sourcePath, transformOptions);

test('returns cache key hash', () => {
expect(oldCacheKey.length).toEqual(32);
Expand All @@ -56,11 +54,9 @@ describe('getCacheKey', () => {

const {default: babelJest}: typeof import('../index') = require('../index');

const newCacheKey = babelJest.getCacheKey(
sourceText,
sourcePath,
transformOptions,
);
const newCacheKey = babelJest
.createTransformer()
.getCacheKey(sourceText, sourcePath, transformOptions);

expect(oldCacheKey).not.toEqual(newCacheKey);
});
Expand All @@ -79,17 +75,15 @@ describe('getCacheKey', () => {

const {default: babelJest}: typeof import('../index') = require('../index');

const newCacheKey = babelJest.getCacheKey(
sourceText,
sourcePath,
transformOptions,
);
const newCacheKey = babelJest
.createTransformer()
.getCacheKey(sourceText, sourcePath, transformOptions);

expect(oldCacheKey).not.toEqual(newCacheKey);
});

test('if `sourceText` value is changing', () => {
const newCacheKey = babelJest.getCacheKey(
const newCacheKey = getCacheKey(
'new source text',
sourcePath,
transformOptions,
Expand All @@ -99,7 +93,7 @@ describe('getCacheKey', () => {
});

test('if `sourcePath` value is changing', () => {
const newCacheKey = babelJest.getCacheKey(
const newCacheKey = getCacheKey(
sourceText,
'new-source-path.js',
transformOptions,
Expand All @@ -109,7 +103,7 @@ describe('getCacheKey', () => {
});

test('if `configString` value is changing', () => {
const newCacheKey = babelJest.getCacheKey(sourceText, sourcePath, {
const newCacheKey = getCacheKey(sourceText, sourcePath, {
...transformOptions,
configString: 'new-config-string',
});
Expand All @@ -131,11 +125,9 @@ describe('getCacheKey', () => {

const {default: babelJest}: typeof import('../index') = require('../index');

const newCacheKey = babelJest.getCacheKey(
sourceText,
sourcePath,
transformOptions,
);
const newCacheKey = babelJest
.createTransformer()
.getCacheKey(sourceText, sourcePath, transformOptions);

expect(oldCacheKey).not.toEqual(newCacheKey);
});
Expand All @@ -154,17 +146,15 @@ describe('getCacheKey', () => {

const {default: babelJest}: typeof import('../index') = require('../index');

const newCacheKey = babelJest.getCacheKey(
sourceText,
sourcePath,
transformOptions,
);
const newCacheKey = babelJest
.createTransformer()
.getCacheKey(sourceText, sourcePath, transformOptions);

expect(oldCacheKey).not.toEqual(newCacheKey);
});

test('if `instrument` value is changing', () => {
const newCacheKey = babelJest.getCacheKey(sourceText, sourcePath, {
const newCacheKey = getCacheKey(sourceText, sourcePath, {
...transformOptions,
instrument: false,
});
Expand All @@ -175,23 +165,15 @@ describe('getCacheKey', () => {
test('if `process.env.NODE_ENV` value is changing', () => {
process.env.NODE_ENV = 'NEW_NODE_ENV';

const newCacheKey = babelJest.getCacheKey(
sourceText,
sourcePath,
transformOptions,
);
const newCacheKey = getCacheKey(sourceText, sourcePath, transformOptions);

expect(oldCacheKey).not.toEqual(newCacheKey);
});

test('if `process.env.BABEL_ENV` value is changing', () => {
process.env.BABEL_ENV = 'NEW_BABEL_ENV';

const newCacheKey = babelJest.getCacheKey(
sourceText,
sourcePath,
transformOptions,
);
const newCacheKey = getCacheKey(sourceText, sourcePath, transformOptions);

expect(oldCacheKey).not.toEqual(newCacheKey);
});
Expand All @@ -200,11 +182,7 @@ describe('getCacheKey', () => {
delete process.version;
process.version = 'new-node-version';

const newCacheKey = babelJest.getCacheKey(
sourceText,
sourcePath,
transformOptions,
);
const newCacheKey = getCacheKey(sourceText, sourcePath, transformOptions);

expect(oldCacheKey).not.toEqual(newCacheKey);
});
Expand Down

0 comments on commit 91a8f0e

Please sign in to comment.