-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #67 from accurat/jest
Add `yarn test` command (Jest)
- Loading branch information
Showing
22 changed files
with
3,381 additions
and
130 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
import { firstDayOfYear } from './App' | ||
|
||
describe(firstDayOfYear, () => { | ||
it('should return Jan 1st of the year (UTC)', () => { | ||
expect(firstDayOfYear(2019).toISOString()).toBe('2019-01-01T00:00:00.000Z') | ||
}) | ||
}) |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require('dotenv').config() // gives precedence to the env variables already present | ||
process.env.NODE_ENV = 'test' | ||
process.env.PUBLIC_URL = '' | ||
|
||
const path = require('path') | ||
const jest = require('jest') | ||
const { isInGitRepository } = require('../utils/git-utils') | ||
|
||
const argv = process.argv.slice(2) | ||
|
||
// Watch unless on CI or explicitly specified not tos | ||
if (!process.env.CI && !argv.includes('--watch=false')) { | ||
// --watch needs a git repository because it runs only the edited test | ||
argv.push(isInGitRepository() ? '--watch' : '--watchAll') | ||
} | ||
|
||
// Load the config | ||
const appDir = process.cwd() | ||
const appJestConfig = path.resolve(appDir, 'jest.config.js') | ||
argv.push('--config', JSON.stringify(appJestConfig)) | ||
|
||
jest.run(argv) |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const accurappConfig = require('jest-config-accurapp') | ||
|
||
module.exports = { | ||
...accurappConfig, | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,7 @@ module.exports = { | |
es6: true, | ||
browser: true, | ||
node: true, | ||
jest: true, | ||
}, | ||
|
||
globals: { | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# jest-config-accurapp | ||
|
||
This package includes the Jest configuration used by Accurapp. | ||
|
||
[For more info, checkout out the main documentation.](https://github.com/accurat/accurapp) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const fs = require('fs') | ||
const babelJest = require('babel-jest') | ||
|
||
const appDir = process.cwd() | ||
const useTypescript = fs.existsSync(`${appDir}/tsconfig.json`) | ||
const babelrc = JSON.parse(fs.readFileSync(`${appDir}/.babelrc`)) | ||
|
||
// Inject the typescript option | ||
if (useTypescript) { | ||
babelrc.presets = [ | ||
...babelrc.presets.filter(p => p !== 'accurapp'), | ||
['accurapp', { typescript: true }], | ||
] | ||
} | ||
|
||
module.exports = babelJest.createTransformer({ | ||
...babelrc, | ||
babelrc: false, | ||
configFile: false, | ||
}) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module.exports = { | ||
// Use newer version of jsdom | ||
testEnvironment: 'jest-environment-jsdom-fifteen', | ||
|
||
setupFiles: [ | ||
// It contains some polyfills such as the isomorphic fetch | ||
'react-app-polyfill/jsdom', | ||
'jest-config-accurapp/setup', | ||
], | ||
|
||
transform: { | ||
// Wrapper around babel-jest | ||
'\\.(js|jsx|ts|tsx)$': 'jest-config-accurapp/babelTransform', | ||
|
||
// Transform simple css files in an empty object | ||
// https://jestjs.io/docs/en/webpack.html | ||
'\\.css$': 'react-scripts/config/jest/cssTransform', | ||
|
||
// Transform all other files into just the filename string | ||
'^(?!.*\\.(js|jsx|ts|tsx|css|json)$)': 'react-scripts/config/jest/fileTransform', | ||
}, | ||
|
||
// Don't transform css modules into an empty object | ||
transformIgnorePatterns: [ | ||
'\\.module\\.(css)$', | ||
], | ||
|
||
// Instead use identity-obj-proxy which outputs the classnames | ||
moduleNameMapper: { | ||
'\\.module\\.(css)$': 'identity-obj-proxy', | ||
}, | ||
|
||
watchPlugins: [ | ||
// Filter your tests by file name or test name | ||
'jest-watch-typeahead/filename', | ||
'jest-watch-typeahead/testname', | ||
], | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"name": "jest-config-accurapp", | ||
"version": "4.0.0", | ||
"description": "Jest configuration used by Accurat", | ||
"repository": "accurat/accurapp", | ||
"license": "MIT", | ||
"keywords": [ | ||
"jest", | ||
"config", | ||
"accurapp", | ||
"accurat" | ||
], | ||
"engines": { | ||
"node": ">=8.6", | ||
"yarn": ">=1.2.1" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"dependencies": { | ||
"@babel/core": "7.4.5", | ||
"babel-jest": "24.9.0", | ||
"identity-obj-proxy": "3.0.0", | ||
"jest": "24.9.0", | ||
"jest-environment-jsdom-fifteen": "1.0.2", | ||
"jest-watch-typeahead": "0.4.2", | ||
"react-app-polyfill": "1.0.5", | ||
"react-scripts": "3.3.0" | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// TODO remove this when it will be integrated in jsdom | ||
// https://github.com/jsdom/jsdom/issues/1721 | ||
function noop() { } | ||
if (typeof window.URL.createObjectURL === 'undefined') { | ||
Object.defineProperty(window.URL, 'createObjectURL', { value: noop }) | ||
} |
Oops, something went wrong.