Skip to content

Commit

Permalink
✅ Fix tests in ESM (#925)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaditmshah authored and carloscuesta committed Sep 27, 2022
1 parent dcbdb44 commit cc0be44
Show file tree
Hide file tree
Showing 7 changed files with 698 additions and 775 deletions.
29 changes: 29 additions & 0 deletions babel.config.json
@@ -0,0 +1,29 @@
{
"presets": [
"@babel/preset-flow"
],
"plugins": [
[
"module-resolver",
{
"alias": {
"@utils": "./src/utils",
"@commands": "./src/commands",
"@constants": "./src/constants"
}
}
],
"@babel/plugin-syntax-import-assertions"
],
"env": {
"test": {
"presets": [
"@babel/preset-env",
"@babel/preset-flow"
],
"plugins": [
"babel-plugin-transform-import-meta"
]
}
}
}
30 changes: 4 additions & 26 deletions package.json
Expand Up @@ -65,6 +65,7 @@
"@babel/preset-env": "7.19.1",
"@babel/preset-flow": "7.18.6",
"babel-plugin-module-resolver": "^4.1.0",
"babel-plugin-transform-import-meta": "^2.2.0",
"codecov": "3.8.3",
"flow-bin": "^0.187.0",
"husky": "8.0.1",
Expand All @@ -75,32 +76,6 @@
"pkg": "5.8.0",
"prettier": "2.7.1"
},
"babel": {
"presets": [
"@babel/preset-flow"
],
"env": {
"test": {
"presets": [
"@babel/preset-env",
"@babel/preset-flow"
]
}
},
"plugins": [
[
"module-resolver",
{
"alias": {
"@utils": "./src/utils",
"@commands": "./src/commands",
"@constants": "./src/constants"
}
}
],
"@babel/plugin-syntax-import-assertions"
]
},
"jest": {
"coverageDirectory": "./coverage/",
"collectCoverage": true,
Expand All @@ -113,7 +88,10 @@
"setupFiles": [
"./test/setupTests.js"
],
"transformIgnorePatterns": [],
"moduleNameMapper": {
"^#ansi-styles$": "<rootDir>/node_modules/chalk/source/vendor/ansi-styles/index.js",
"^#supports-color$": "<rootDir>/node_modules/chalk/source/vendor/supports-color/index.js",
"@utils/(.*)$": "<rootDir>/src/utils/$1",
"@commands/(.*)$": "<rootDir>/src/commands/$1",
"@constants/(.*)$": "<rootDir>/src/constants/$1"
Expand Down
2 changes: 1 addition & 1 deletion src/cli.js
Expand Up @@ -32,7 +32,7 @@ const cli = meow(
$ gitmoji bug linter -s
`,
{
importMeta: import.meta,
importMeta: { url: import.meta.url },
flags: {
[FLAGS.COMMIT]: { type: 'boolean', alias: 'c' },
[FLAGS.CONFIG]: { type: 'boolean', alias: 'g' },
Expand Down
1 change: 1 addition & 0 deletions test/__snapshots__/cli.spec.js.snap
Expand Up @@ -58,6 +58,7 @@ exports[`cli should match meow with cli information 1`] = `
"type": "boolean",
},
},
"importMeta": "import.meta.url",
},
],
]
Expand Down
2 changes: 2 additions & 0 deletions test/cli.spec.js
Expand Up @@ -16,6 +16,8 @@ describe('cli', () => {
})

it('should match meow with cli information', () => {
meow.mock.calls[0][1].importMeta = 'import.meta.url'

expect(meow.mock.calls).toMatchSnapshot()
})

Expand Down
3 changes: 3 additions & 0 deletions test/setupTests.js
Expand Up @@ -3,6 +3,9 @@ import fetchMock from 'jest-fetch-mock'
jest.setMock('node-fetch', fetchMock)
jest.mock('path-exists')
jest.mock('fs')
jest
.requireMock('fs')
.readFileSync.mockImplementation(jest.requireActual('fs').readFileSync)
jest.mock('ora', () =>
jest.fn().mockReturnValue({
start: jest.fn(function () {
Expand Down

0 comments on commit cc0be44

Please sign in to comment.