Skip to content

Commit

Permalink
chore(jest): setup jest with esm
Browse files Browse the repository at this point in the history
Running jest without babel.

Using [email protected] because of the following error:

```
TypeError: Jest: a transform must export a `process` function.
```

See kenotron/esm-jest#5 (comment)
  • Loading branch information
topheman committed Jul 16, 2019
1 parent a723b60 commit 611572e
Show file tree
Hide file tree
Showing 5 changed files with 2,394 additions and 24 deletions.
9 changes: 9 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
transform: {
"\\.m?jsx?$": "esm"
},
moduleNameMapper: {
"^anotherRoot/(.*)$": "<rootDir>/lib/anotherRoot/$1"
},
transformIgnorePatterns: []
};
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"lint:precommit": "echo \"No precommit linting yet\" && exit 0",
"test:precommit": "npm test",
"pretty": "npx prettier --write '**/*.{tsx,ts,js,jsx,json,css,scss,md}'",
"test": "echo \"No test specified yet\" && exit 0"
"test": "npx jest --runInBand --no-cache --config jest.config.js"
},
"lint-staged": {
"**/*.{tsx,ts,js,jsx,json,css,scss,md}": [
Expand All @@ -24,7 +24,9 @@
"author": "Christophe Rosset <[email protected]> (http://labs.topheman.com/)",
"license": "MIT",
"devDependencies": {
"esm": "3.1.0",
"husky": "^1.3.1",
"jest": "^24.8.0",
"lint-staged": "^8.1.0",
"prettier": "1.18.2",
"serve": "^11.1.0"
Expand Down
2 changes: 1 addition & 1 deletion src/js/logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function createStore(initialReducer, initialState = {}, enhancer) {
};
}

function reducer(state = 0, action) {
export function reducer(state = 0, action) {
switch (action.type) {
case "ADD":
return state + 1;
Expand Down
7 changes: 7 additions & 0 deletions src/js/logic.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { reducer } from "./logic";

describe("logic.reducer", () => {
it("default state - ADD function should resolve to 1", () => {
expect(reducer(undefined, { type: "ADD" })).toBe(1);
});
});
Loading

0 comments on commit 611572e

Please sign in to comment.