Skip to content

Commit 6381870

Browse files
committed
fix(jest): Let jest keep using CommonJS
ESM is barely supported in Jest atm, pending stabilization of VM modules in node.js This keeps transpiling to CommonJS for Jest's sake
1 parent c594569 commit 6381870

14 files changed

Lines changed: 328 additions & 84 deletions

.eslintrc.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports = {
22
parser: '@typescript-eslint/parser', // Specifies the ESLint parser
33
parserOptions: {
4-
ecmaVersion: "latest", // Allows for the parsing of modern ECMAScript features
4+
ecmaVersion: 'latest', // Allows for the parsing of modern ECMAScript features
55
sourceType: 'module', // Allows for the use of imports
66
},
77
extends: [

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20.15.0
1+
20.16.0

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ COPY package.json package-lock.json ./
55
RUN npm install --production
66
COPY . .
77

8-
CMD cd /app && npm start
8+
CMD ["npm", "start"]

babel.config.cjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module.exports = {
2-
presets: [["@babel/preset-env", { targets: { node: "current" } }], "@babel/preset-typescript"],
3-
plugins: ["babel-plugin-transform-import-meta"],
4-
}
2+
presets: [['@babel/preset-env', { targets: { node: 'current' } }], '@babel/preset-typescript'],
3+
plugins: ['babel-plugin-transform-import-meta'],
4+
}

index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { getGithubUsersFromGoogle } from './src/google'
2-
import { getGithubUsersFromGithub, addUsersToGitHubOrg, removeUsersFromGitHubOrg } from './src/github'
3-
import { config } from './src/config'
1+
import { getGithubUsersFromGoogle } from './src/google.js'
2+
import { getGithubUsersFromGithub, addUsersToGitHubOrg, removeUsersFromGitHubOrg } from './src/github.js'
3+
import { config } from './src/config.js'
44

55
export async function run(): Promise<void> {
66
const googleUsers = await getGithubUsersFromGoogle()

jest.config.cjs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1+
// This project uses ESM at runtime. Since ESM is very much unsupported in jest for now, we have to transform ESM things to CJS format
2+
// Jest is transforming own code using the babel-jest and we need to do the same for third party ESM code
3+
// If you add any third party ESM only modules from npm, be sure to add them here:
4+
const ESM_MODULES = ['@octokit/.*', 'before-after-hook', 'universal-github-app-jwt', 'universal-user-agent']
5+
16
module.exports = {
2-
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$',
3-
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
4-
testEnvironment: 'node',
57
coverageReporters: ['lcovonly', 'text'],
68
collectCoverage: true,
79
coverageDirectory: 'coverage',
8-
restoreMocks: true,
9-
resetMocks: true,
1010
collectCoverageFrom: [
1111
'**/*.ts',
1212
'**/*.js',
@@ -16,4 +16,13 @@ module.exports = {
1616
'!coverage/**',
1717
'!jest.config.js',
1818
],
19+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
20+
moduleNameMapper: {
21+
'^(\\.{1,2}/.*)\\.js$': '$1',
22+
},
23+
restoreMocks: true,
24+
resetMocks: true,
25+
testEnvironment: 'node',
26+
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$',
27+
transformIgnorePatterns: [`/node_modules/(?!(${ESM_MODULES.join('|')})/)`],
1928
}

0 commit comments

Comments
 (0)