Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump jest and @types/jest #626

Merged
merged 3 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 72 additions & 63 deletions loom.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,81 +26,90 @@ function jestWorkspaceConfigPlugin() {
'../../tests/setup/setup-jest.ts',
]);
configure.jestConfig?.hook((config) => {
const projects = forkRemixProject(
config.projects as Config.InitialProjectOptions[],
);
return {...config, projects, testTimeout: 30000};
return {
...config,
projects: configureProjects(
config.projects as Config.InitialProjectOptions[],
),
testTimeout: 30000,
};
});
});
});
},
);
}

function configureProjects(projects: Config.InitialProjectOptions[]) {
return setTransformIgnorePatterns(projects).reduce((acc, project) => {
if (
typeof project !== 'string' &&
project.displayName === 'shopify-app-remix'
) {
return acc.concat(forkRemixProject(project));
}

return acc.concat(project);
}, [] as Config.InitialProjectOptions[]);
}

/**
* Some ESM-only packages need to be included in jest transforms for them to work. This function adds them to the
* transformIgnorePatterns array for each project.
*/
function setTransformIgnorePatterns(projects: Config.InitialProjectOptions[]) {
return projects.map((project) => {
return {
...project,
transformIgnorePatterns: [
...(project.transformIgnorePatterns || []),
'node_modules/(?!@web3-storage)',
],
};
});
}

/**
* The remix project is a bit of a special case because we need to run its tests in two different environments, one
* using jsdom and the other, node.
*
* To achieve that, we create two separate projects which copy all of the settings from the original project, overriding
* the test environment and making them mutually exclusive.
*/
function forkRemixProject(projects: Config.InitialProjectOptions[]) {
return projects.reduce((acc, project) => {
if (
typeof project !== 'string' &&
project.displayName === 'shopify-app-remix'
) {
return acc.concat(
[
{
...project,
displayName: 'shopify-app-remix-react',
testEnvironment: 'jsdom',
testPathIgnorePatterns: ['src/server'],
},
],
[
{
...project,
setupFilesAfterEnv: [
...(project.setupFilesAfterEnv ?? []),
'../../packages/shopify-app-remix/src/server/adapters/node/__tests__/setup-jest.ts',
],
displayName: 'shopify-app-remix-server-node',
testEnvironment: 'node',
testPathIgnorePatterns: [
'src/react',
'src/server/adapters/__tests__',
],
},
],
[
{
...project,
setupFilesAfterEnv: [
...(project.setupFilesAfterEnv ?? []),
'../../packages/shopify-app-remix/src/server/adapters/vercel/__tests__/setup-jest.ts',
],
displayName: 'shopify-app-remix-server-vercel',
testEnvironment: 'node',
testPathIgnorePatterns: [
'src/react',
'src/server/adapters/__tests__',
],
},
],
[
{
...project,
testRegex: undefined,
displayName: 'shopify-app-remix-server-adapters',
testMatch: ['<rootDir>/src/server/adapters/__tests__/**/*'],
testEnvironment: 'node',
},
],
);
} else {
return acc.concat(project);
}
}, [] as Config.InitialProjectOptions[]);
function forkRemixProject(project: Config.InitialProjectOptions) {
return [
{
...project,
displayName: 'shopify-app-remix-react',
testEnvironment: 'jsdom',
testPathIgnorePatterns: ['src/server'],
},
{
...project,
setupFilesAfterEnv: [
...(project.setupFilesAfterEnv ?? []),
'../../packages/shopify-app-remix/src/server/adapters/node/__tests__/setup-jest.ts',
],
displayName: 'shopify-app-remix-server-node',
testEnvironment: 'node',
testPathIgnorePatterns: ['src/react', 'src/server/adapters/__tests__'],
},
{
...project,
setupFilesAfterEnv: [
...(project.setupFilesAfterEnv ?? []),
'../../packages/shopify-app-remix/src/server/adapters/vercel/__tests__/setup-jest.ts',
],
displayName: 'shopify-app-remix-server-vercel',
testEnvironment: 'node',
testPathIgnorePatterns: ['src/react', 'src/server/adapters/__tests__'],
},
{
...project,
testRegex: undefined,
displayName: 'shopify-app-remix-server-adapters',
testMatch: ['<rootDir>/src/server/adapters/__tests__/**/*'],
testEnvironment: 'node',
},
];
}
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@
"@shopify/loom-plugin-prettier": "^2.0.1",
"@shopify/prettier-config": "^1.1.2",
"@shopify/typescript-configs": "^5.1.0",
"@types/jest": "^29.5.1",
"@types/jest": "^29.5.12",
"eslint": "^8.55.0",
"eslint-plugin-prettier": "^5.1.3",
"jest": "^29.1.0",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"jest-fetch-mock": "^3.0.3",
"jest-runner-eslint": "^2.1.2",
"prettier": "^3.2.5",
Expand All @@ -35,6 +36,11 @@
"typescript": "5.3.3"
},
"dependencies": {},
"resolutions": {
"jest": "^29.7.0",
"jest-circus": "^29.7.0",
"ts-jest": "^29.1.2"
},
"workspaces": [
"packages/*"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ describe('redirectToAuth', () => {
shop: TEST_SHOP,
host: BASE64_HOST,
embedded: '1',
redirectUri: `https://${shopify.api.config.hostName}/auth?shop=${TEST_SHOP}&host=${BASE64_HOST}`,
});
const response = await request(app)
.get(`/redirect-to-auth?${expectedParams.toString()}`)
Expand All @@ -74,11 +75,10 @@ describe('redirectToAuth', () => {
response.header.location,
'http://not-a-real-host.myshopify.io',
);
const params = Object.fromEntries(url.searchParams.entries());

expect(url.host).toBe('not-a-real-host.myshopify.io');
expect(url.pathname).toBe('/exitiframe');
expect(params).toMatchObject(expectedParams);
expect(url.searchParams.toString()).toEqual(expectedParams.toString());
});

it('fails with invalid shop', async () => {
Expand Down
Loading
Loading