Last active
June 26, 2019 07:08
-
-
Save hiptkang/9f539a7fc8fb763950c6e40491833d2f to your computer and use it in GitHub Desktop.
minimal-setup for jest and lint using babel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// .eslintrc.js | |
const config = { | |
"extends" : "airbnb", | |
"parser": "babel-eslint", | |
"rules": { | |
"no-plusplus": 2, | |
"no-console": "off", | |
}, | |
"env": { | |
"jest": true | |
} | |
} | |
module.exports = config; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
node_modules/ | |
logs/ | |
coverage/ | |
npm-debug.log | |
.next | |
build/ | |
.env | |
.DS_Store | |
.vscode | |
tmp/ | |
tmp-*/ | |
log/ | |
test-results/ | |
public/*bundle.* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// babel.config.js | |
module.exports = { | |
presets: [ | |
[ | |
'@babel/preset-env', | |
{ | |
targets: { | |
node: 'current', | |
}, | |
}, | |
], | |
], | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ yarn lint ./ | |
yarn run v1.13.0 | |
$ eslint --ignore-path .gitignore --ignore-pattern '**/dist/' --ext .jsx,.js ./ | |
Done in 0.82s. | |
$ yarn test | |
yarn run v1.13.0 | |
$ jest | |
Determining test suites to run... | |
# GLOBAL TEST SETUP # | |
PASS test ./hello.spec.js | |
✓ hello should return hello with my name (2ms) | |
Test Suites: 1 passed, 1 total | |
Tests: 1 passed, 1 total | |
Snapshots: 0 total | |
Time: 0.399s, estimated 1s | |
Ran all test suites. | |
# GLOBAL TEST TEARDOWN # | |
Done in 0.99s. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// hello.js | |
const hello = name => `Hello, ${name}`; | |
module.exports = hello; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// hello.spec.js | |
import hello from './hello'; | |
test('hello should return hello with my name', () => { | |
const res = hello('my name'); | |
expect(res).toEqual('Hello, my name'); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// jest.config.js | |
const ignoredPaths = [ | |
'<rootDir>/node_modules/', | |
'<rootDir>/dist', | |
'<rootDir>/test/', | |
]; | |
module.exports = { | |
displayName: 'test', | |
verbose: true, | |
testEnvironment: 'node', | |
testPathIgnorePatterns: ignoredPaths, | |
setupFilesAfterEnv: ['<rootDir>/test/setupTestFramework.js'], | |
globalSetup: '<rootDir>/test/setup.js', | |
globalTeardown: '<rootDir>/test/teardown.js', | |
moduleNameMapper: { | |
}, | |
resetModules: false, | |
transform: { | |
'^.+\\.js?$': '<rootDir>/node_modules/babel-jest', | |
'^.+\\.ts?$': '<rootDir>/node_modules/babel-jest', | |
}, | |
testRegex: '((\\.|/)(test|spec))\\.(js?|ts?)$', | |
moduleFileExtensions: ['ts', 'js'], | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "minsetup-jest-lint-babel", | |
"version": "1.0.0", | |
"description": "minimal setup for jest and lint using babel", | |
"main": "hello.js", | |
"scripts": { | |
"lint": "eslint --ignore-path .gitignore --ignore-pattern '**/dist/' --ext .jsx,.js", | |
"lint:fix": "npm run lint -- --fix", | |
"test": "jest" | |
}, | |
"author": "hyunsamk", | |
"license": "ISC", | |
"dependencies": { | |
}, | |
"devDependencies": { | |
"@babel/core": "^7.4.3", | |
"@babel/preset-env": "^7.4.5", | |
"babel-eslint": "^10.0.2", | |
"babel-jest": "^24.8.0", | |
"eslint": "^5.16.0", | |
"eslint-config-airbnb": "^17.1.0", | |
"eslint-plugin-import": "^2.17.0", | |
"jest": "^24.8.0", | |
"jest-junit": "^6.4.0" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// test/setup.js | |
module.exports = () => { | |
console.log('# GLOBAL TEST SETUP #'); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// test/setupTe...js | |
// this file is ran right after the test framework is setup for some test file. | |
jest.setTimeout(5000); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// test/teardown.js | |
module.exports = () => { | |
console.log('# GLOBAL TEST TEARDOWN #'); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment