Skip to content

Commit cfe5131

Browse files
author
Daniel Del Core
committed
adds various test suite changes pre-esm
1 parent 8489e26 commit cfe5131

File tree

4 files changed

+31
-12
lines changed

4 files changed

+31
-12
lines changed

jest.config.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
1+
/** @type {import('ts-jest').JestConfigWithTsJest} */
12
module.exports = {
23
testEnvironment: 'node',
34
transform: {
4-
'^.+\\.ts$': [
5+
'\\.[jt]sx?$': [
56
'ts-jest',
67
{
78
tsconfig: 'tsconfig.json',
9+
diagnostics: { ignoreCodes: [1343] },
10+
astTransformers: {
11+
before: [
12+
{
13+
path: 'node_modules/ts-jest-mock-import-meta',
14+
options: {
15+
metaObjectReplacement: { url: 'https://www.url.com' },
16+
},
17+
},
18+
],
19+
},
820
},
921
],
1022
},
@@ -16,6 +28,7 @@ module.exports = {
1628
'jest-watch-typeahead/testname',
1729
],
1830
moduleNameMapper: {
31+
'(.+)\\.js$': '$1',
1932
'@hypermod/(.*)$': '<rootDir>/packages/$1/src',
2033
'@codeshift/(.*)$': '<rootDir>/packages/$1/src',
2134
},

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
"semver": "^7.3.5",
7070
"tar": "^6.1.0",
7171
"ts-jest": "^29.2.5",
72+
"ts-jest-mock-import-meta": "^1.2.0",
7273
"ts-loader": "^6.2.1",
7374
"ts-node": "^10.9.1",
7475
"tslib": "^2.2.0",

packages/fetcher/src/index.spec.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ const mockBasePath = path.join(__dirname, 'path', 'to');
1515

1616
const mockConfig = {
1717
transforms: {
18-
'10.0.0': 'path/to/transform.js',
18+
'10.0.0': 'path/to/transform.ts',
1919
},
2020
};
2121

2222
describe('fetcher', () => {
2323
let mockMatchedPaths: string[] = [];
2424

2525
beforeEach(() => {
26-
mockMatchedPaths = [path.join(mockBasePath, 'hypermod.config.js')];
26+
mockMatchedPaths = [path.join(mockBasePath, 'hypermod.config.ts')];
2727

2828
(globby as unknown as jest.Mock).mockImplementation(() =>
2929
Promise.resolve(mockMatchedPaths),
@@ -38,10 +38,10 @@ describe('fetcher', () => {
3838

3939
describe('fetchConfig', () => {
4040
it('fetches config with default export', async () => {
41-
const mockFilePath = `${__dirname}/path/to/hypermod.config.js`;
41+
const mockFilePath = `${__dirname}/path/to/hypermod.config.ts`;
4242

4343
jest.mock(
44-
`${__dirname}/path/to/hypermod.config.js`,
44+
`${__dirname}/path/to/hypermod.config.ts`,
4545
() => ({ __esModule: true, default: mockConfig }),
4646
{ virtual: true },
4747
);
@@ -54,7 +54,7 @@ describe('fetcher', () => {
5454

5555
it('fetches config with named export', async () => {
5656
jest.mock(
57-
path.join(mockBasePath, 'hypermod.config.js'),
57+
path.join(mockBasePath, 'hypermod.config.ts'),
5858
() => mockConfig,
5959
{
6060
virtual: true,
@@ -65,7 +65,7 @@ describe('fetcher', () => {
6565

6666
expect(configMeta!.config).toEqual(mockConfig);
6767
expect(configMeta!.filePath).toEqual(
68-
path.join(mockBasePath, 'hypermod.config.js'),
68+
path.join(mockBasePath, 'hypermod.config.ts'),
6969
);
7070
});
7171

@@ -106,7 +106,7 @@ describe('fetcher', () => {
106106

107107
describe('fetchPackage', () => {
108108
it('correctly fetches package and returns a config', async () => {
109-
const mockFilePath = 'path/to/config.hypermod.js';
109+
const mockFilePath = 'path/to/config.hypermod.ts';
110110
const mockPackageManager = {
111111
install: jest.fn(),
112112
getInfo: jest.fn().mockReturnValue({ location: mockFilePath }),
@@ -154,7 +154,7 @@ describe('fetcher', () => {
154154

155155
expect(configMeta!.config).toEqual(mockConfig);
156156
expect(configMeta!.filePath).toEqual(
157-
mockBasePath + '/hypermod.config.js',
157+
mockBasePath + '/hypermod.config.ts',
158158
);
159159
});
160160

@@ -177,7 +177,7 @@ describe('fetcher', () => {
177177
install: jest.fn(),
178178
require: jest.fn().mockReturnValueOnce(mockConfig),
179179
getInfo: jest.fn().mockReturnValue({
180-
location: mockBasePath + '/index.js',
180+
location: mockBasePath + '/index.ts',
181181
}),
182182
};
183183

@@ -187,15 +187,15 @@ describe('fetcher', () => {
187187
);
188188

189189
expect(configMeta!.config).toEqual(mockConfig);
190-
expect(configMeta!.filePath).toEqual(mockBasePath + '/index.js');
190+
expect(configMeta!.filePath).toEqual(mockBasePath + '/index.ts');
191191
});
192192

193193
it('throws if entrypoint-based config does not contain a valid config (and there are no config files available elsewhere)', async () => {
194194
const mockPackageManager = {
195195
install: jest.fn(),
196196
require: jest.fn().mockReturnValueOnce({}),
197197
getInfo: jest.fn().mockReturnValue({
198-
location: mockBasePath + '/index.js',
198+
location: mockBasePath + '/index.ts',
199199
}),
200200
};
201201

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7981,6 +7981,11 @@ trim-newlines@^3.0.0:
79817981
resolved "https://registry.npmjs.org/trim-newlines/-/trim-newlines-3.0.1.tgz"
79827982
integrity sha512-c1PTsA3tYrIsLGkJkzHF+w9F2EyxfXGo4UyJc4pFL++FMjnq0HJS69T3M7d//gKrFKwy429bouPescbjecU+Zw==
79837983

7984+
ts-jest-mock-import-meta@^1.2.0:
7985+
version "1.2.0"
7986+
resolved "https://registry.yarnpkg.com/ts-jest-mock-import-meta/-/ts-jest-mock-import-meta-1.2.0.tgz#6fb12a1fa47f70f9335a288e888cbacf592c4dc1"
7987+
integrity sha512-r2+TH6d8LHBXqLTXjJh1KfTZoMvGV0hdn9gwickNVcwS2Co2/mewGjj0XDVEPLg5MVfZVHUFQ9O09anURA3KCw==
7988+
79847989
ts-jest@^29.2.5:
79857990
version "29.2.5"
79867991
resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-29.2.5.tgz#591a3c108e1f5ebd013d3152142cb5472b399d63"

0 commit comments

Comments
 (0)