forked from Shopify/shopify-app-js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathloom.config.ts
130 lines (121 loc) · 3.95 KB
/
loom.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import {createWorkspace, createWorkspacePlugin} from '@shopify/loom';
import {buildLibraryWorkspace} from '@shopify/loom-plugin-build-library';
import {eslint} from '@shopify/loom-plugin-eslint';
import {prettier} from '@shopify/loom-plugin-prettier';
import {Config} from '@jest/types';
import type {} from '@shopify/loom-plugin-jest';
export default createWorkspace((workspace) => {
workspace.use(
buildLibraryWorkspace(),
eslint(),
prettier({files: '**/*.{json,md}'}),
jestWorkspaceConfigPlugin(),
);
});
function jestWorkspaceConfigPlugin() {
return createWorkspacePlugin(
'shopify-app-js--workplace-setup',
({tasks: {test}}) => {
test.hook(({hooks}) => {
hooks.configure.hook((configure) => {
configure.jestSetupFilesAfterEnv?.hook((files) => [
...files,
'../../tests/setup/setup-jest.ts',
]);
configure.jestConfig?.hook((config) => {
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));
}
/*
* drizzle-orm is a special case because it seems to be ESM-only, so we need jest to run it through babel for the
* tests to work.
*/
if (
typeof project !== 'string' &&
project.displayName === 'shopify-app-session-storage-drizzle'
) {
project.transformIgnorePatterns = [
...(project.transformIgnorePatterns ?? []),
'node_modules/(?!drizzle-orm)',
];
}
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(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',
},
];
}