Skip to content

Commit

Permalink
adds various test suite changes pre-esm
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Del Core committed Sep 21, 2024
1 parent 8489e26 commit 425fdef
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 12 deletions.
6 changes: 6 additions & 0 deletions .changeset/hungry-spies-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@hypermod/validator': patch
'@hypermod/cli': patch
---

Various configuration changes in support of ESM.
15 changes: 14 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
testEnvironment: 'node',
transform: {
'^.+\\.ts$': [
'\\.[jt]sx?$': [
'ts-jest',
{
tsconfig: 'tsconfig.json',
diagnostics: { ignoreCodes: [1343] },
astTransformers: {
before: [
{
path: 'node_modules/ts-jest-mock-import-meta',
options: {
metaObjectReplacement: { url: 'https://www.url.com' },
},
},
],
},
},
],
},
Expand All @@ -16,6 +28,7 @@ module.exports = {
'jest-watch-typeahead/testname',
],
moduleNameMapper: {
'(.+)\\.js$': '$1',
'@hypermod/(.*)$': '<rootDir>/packages/$1/src',
'@codeshift/(.*)$': '<rootDir>/packages/$1/src',
},
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"semver": "^7.3.5",
"tar": "^6.1.0",
"ts-jest": "^29.2.5",
"ts-jest-mock-import-meta": "^1.2.0",
"ts-loader": "^6.2.1",
"ts-node": "^10.9.1",
"tslib": "^2.2.0",
Expand Down
22 changes: 11 additions & 11 deletions packages/fetcher/src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ const mockBasePath = path.join(__dirname, 'path', 'to');

const mockConfig = {
transforms: {
'10.0.0': 'path/to/transform.js',
'10.0.0': 'path/to/transform.ts',
},
};

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

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

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

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

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

it('fetches config with named export', async () => {
jest.mock(
path.join(mockBasePath, 'hypermod.config.js'),
path.join(mockBasePath, 'hypermod.config.ts'),
() => mockConfig,
{
virtual: true,
Expand All @@ -65,7 +65,7 @@ describe('fetcher', () => {

expect(configMeta!.config).toEqual(mockConfig);
expect(configMeta!.filePath).toEqual(
path.join(mockBasePath, 'hypermod.config.js'),
path.join(mockBasePath, 'hypermod.config.ts'),
);
});

Expand Down Expand Up @@ -106,7 +106,7 @@ describe('fetcher', () => {

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

expect(configMeta!.config).toEqual(mockConfig);
expect(configMeta!.filePath).toEqual(
mockBasePath + '/hypermod.config.js',
mockBasePath + '/hypermod.config.ts',
);
});

Expand All @@ -177,7 +177,7 @@ describe('fetcher', () => {
install: jest.fn(),
require: jest.fn().mockReturnValueOnce(mockConfig),
getInfo: jest.fn().mockReturnValue({
location: mockBasePath + '/index.js',
location: mockBasePath + '/index.ts',
}),
};

Expand All @@ -187,15 +187,15 @@ describe('fetcher', () => {
);

expect(configMeta!.config).toEqual(mockConfig);
expect(configMeta!.filePath).toEqual(mockBasePath + '/index.js');
expect(configMeta!.filePath).toEqual(mockBasePath + '/index.ts');
});

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

Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7981,6 +7981,11 @@ trim-newlines@^3.0.0:
resolved "https://registry.npmjs.org/trim-newlines/-/trim-newlines-3.0.1.tgz"
integrity sha512-c1PTsA3tYrIsLGkJkzHF+w9F2EyxfXGo4UyJc4pFL++FMjnq0HJS69T3M7d//gKrFKwy429bouPescbjecU+Zw==

ts-jest-mock-import-meta@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/ts-jest-mock-import-meta/-/ts-jest-mock-import-meta-1.2.0.tgz#6fb12a1fa47f70f9335a288e888cbacf592c4dc1"
integrity sha512-r2+TH6d8LHBXqLTXjJh1KfTZoMvGV0hdn9gwickNVcwS2Co2/mewGjj0XDVEPLg5MVfZVHUFQ9O09anURA3KCw==

ts-jest@^29.2.5:
version "29.2.5"
resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-29.2.5.tgz#591a3c108e1f5ebd013d3152142cb5472b399d63"
Expand Down

0 comments on commit 425fdef

Please sign in to comment.