Skip to content

Commit

Permalink
use Babel instead of ts-jest to speed up and simplify tests
Browse files Browse the repository at this point in the history
Removed typechecking from jest tests (by removing ts-jest and just using Babel's TypeScript transpilation, per https://jestjs.io/docs/en/getting-started#using-typescript). This makes tests run faster (~2s vs. ~9s for a single test after making a change to a `.ts` file) and simplifies their build configuration (by removing an unnecessary tool, ts-jest, from our toolchain). You should instead rely on your editor (and CI) for typechecking.

Babel is a good choice because it is the standard for transpilation, and tslint is being deprecated in favor of Babel + eslint (so we need to switch soon anyway to get the latest lint rules, such as those for React hooks).
  • Loading branch information
sqs committed Jun 10, 2019
1 parent 4e06936 commit da87d7f
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 151 deletions.
40 changes: 25 additions & 15 deletions babel.config.js
@@ -1,19 +1,29 @@
// @ts-check

/** @type {import('@babel/core').TransformOptions} */
const config = {
presets: [
[
'@babel/preset-env',
{
modules: false,
useBuiltIns: 'entry',
},
/** @type {import('@babel/core').ConfigFunction} */
module.exports = api => {
const isTest = api.env('test')
api.cache.forever()

return {
presets: [
[
'@babel/preset-env',
{
// Node (used for testing) doesn't support modules, so compile to CommonJS for testing.
modules: isTest ? 'commonjs' : false,
useBuiltIns: 'entry',
},
],
'@babel/preset-typescript',
'@babel/preset-react',
],
'@babel/preset-typescript',
'@babel/preset-react',
],
plugins: ['@babel/plugin-syntax-dynamic-import', 'babel-plugin-lodash'],
}
plugins: [
'@babel/plugin-syntax-dynamic-import',
'babel-plugin-lodash',

module.exports = config
// Node 12 (released 2019 Apr 23) supports these natively, so we can remove this plugin soon.
'@babel/plugin-proposal-class-properties',
],
}
}
11 changes: 0 additions & 11 deletions jest.config.base.js
Expand Up @@ -11,10 +11,7 @@ const config = {
collectCoverage: !!process.env.CI,
coverageDirectory: '<rootDir>/coverage',
coveragePathIgnorePatterns: [/\.test\.tsx?$/.source],
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json'],
preset: 'ts-jest/presets/js-with-ts',
roots: ['<rootDir>/src'],
transform: { '^.+\\.[jt]sx?$': 'ts-jest' },

// Transform packages that do not distribute CommonJS packages (typically because they only distribute ES6
// modules). If you get an error from jest like "Jest encountered an unexpected token. ... SyntaxError:
Expand All @@ -30,14 +27,6 @@ const config = {
// By default, don't clutter `yarn test --watch` output with the full coverage table. To see it, use the
// `--coverageReporters text` jest option.
coverageReporters: ['json', 'lcov', 'text-summary'],
globals: {
'ts-jest': {
diagnostics: {
pathRegex: '(browser|shared|web)/src',
warnOnly: true,
},
},
},

setupFiles: [path.join(__dirname, 'shared/dev/mockDate.js'), path.join(__dirname, 'shared/dev/globalThis.js')],
}
Expand Down
6 changes: 4 additions & 2 deletions package.json
Expand Up @@ -47,9 +47,12 @@
},
"devDependencies": {
"@babel/core": "^7.2.2",
"@babel/plugin-proposal-class-properties": "^7.2.3",
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
"@babel/polyfill": "^7.2.5",
"@babel/preset-env": "^7.2.3",
"@babel/preset-react": "^7.0.0",
"@babel/preset-typescript": "^7.3.3",
"@babel/runtime": "^7.2.0",
"@gql2ts/from-schema": "^1.10.1",
"@gql2ts/language-typescript": "^1.9.0",
Expand Down Expand Up @@ -124,6 +127,7 @@
"@types/webpack-dev-server": "3.1.5",
"@types/whatwg-url": "6.4.0",
"autoprefixer": "^9.6.0",
"babel-jest": "^24.8.0",
"babel-loader": "^8.0.6",
"babel-plugin-lodash": "^3.3.4",
"browserslist": "^4.6.1",
Expand Down Expand Up @@ -171,11 +175,9 @@
"style-loader": "^0.23.1",
"stylelint": "^10.1.0",
"terser-webpack-plugin": "^1.3.0",
"ts-jest": "^24.0.2",
"ts-loader": "^6.0.2",
"ts-node": "^8.2.0",
"tslint": "^5.17.0",
"typedoc": "^0.14.2",
"typescript": "^3.5.1",
"utc-version": "^2.0.0",
"webpack": "^4.33.0",
Expand Down
Expand Up @@ -11,7 +11,7 @@ Object {
}
}
>
<Unknown
<CompletionWidgetDropdown
completionListOrError={
Object {
"items": Array [
Expand Down
2 changes: 1 addition & 1 deletion shared/src/hover/__snapshots__/HoverOverlay.test.tsx.snap
Expand Up @@ -288,7 +288,7 @@ exports[`HoverOverlay actions present, hover loading 1`] = `
<div
className="hover-overlay__row hover-overlay__loader-row"
>
<Unknown
<LoadingSpinner
className="icon-inline"
/>
</div>
Expand Down
Expand Up @@ -37,12 +37,7 @@ exports[`<HierarchicalLocationsView /> displays a single location when complete
d="M23,42.4c1.3,0,2.4-1.1,2.4-2.4s-1.1-2.4-2.4-2.4s-2.4,1.1-2.4,2.4S21.7,42.4,23,42.4z"
/>
<path
d="M50,16h-1.5c-0.3,0-0.5,0.2-0.5,0.5v35c0,0.3-0.2,0.5-0.5,0.5h-27c-0.5,0-1-0.2-1.4-0.6l-0.6-0.6c-0.1-0.1-0.1-0.2-0.1-0.4
c0-0.3,0.2-0.5,0.5-0.5H44c1.1,0,2-0.9,2-2V12c0-1.1-0.9-2-2-2H14c-1.1,0-2,0.9-2,2v36.3c0,1.1,0.4,2.1,1.2,2.8l3.1,3.1
c1.1,1.1,2.7,1.8,4.2,1.8H50c1.1,0,2-0.9,2-2V18C52,16.9,51.1,16,50,16z M19,20c0-2.2,1.8-4,4-4c1.4,0,2.8,0.8,3.5,2
c1.1,1.9,0.4,4.3-1.5,5.4V33c1-0.6,2.3-0.9,4-0.9c1,0,2-0.5,2.8-1.3C32.5,30,33,29.1,33,28v-0.6c-1.2-0.7-2-2-2-3.5
c0-2.2,1.8-4,4-4c2.2,0,4,1.8,4,4c0,1.5-0.8,2.7-2,3.5h0c-0.1,2.1-0.9,4.4-2.5,6c-1.6,1.6-3.4,2.4-5.5,2.5c-0.8,0-1.4,0.1-1.9,0.3
c-0.2,0.1-1,0.8-1.2,0.9C26.6,38,27,38.9,27,40c0,2.2-1.8,4-4,4s-4-1.8-4-4c0-1.5,0.8-2.7,2-3.4V23.4C19.8,22.7,19,21.4,19,20z"
d="M50,16h-1.5c-0.3,0-0.5,0.2-0.5,0.5v35c0,0.3-0.2,0.5-0.5,0.5h-27c-0.5,0-1-0.2-1.4-0.6l-0.6-0.6c-0.1-0.1-0.1-0.2-0.1-0.4 c0-0.3,0.2-0.5,0.5-0.5H44c1.1,0,2-0.9,2-2V12c0-1.1-0.9-2-2-2H14c-1.1,0-2,0.9-2,2v36.3c0,1.1,0.4,2.1,1.2,2.8l3.1,3.1 c1.1,1.1,2.7,1.8,4.2,1.8H50c1.1,0,2-0.9,2-2V18C52,16.9,51.1,16,50,16z M19,20c0-2.2,1.8-4,4-4c1.4,0,2.8,0.8,3.5,2 c1.1,1.9,0.4,4.3-1.5,5.4V33c1-0.6,2.3-0.9,4-0.9c1,0,2-0.5,2.8-1.3C32.5,30,33,29.1,33,28v-0.6c-1.2-0.7-2-2-2-3.5 c0-2.2,1.8-4,4-4c2.2,0,4,1.8,4,4c0,1.5-0.8,2.7-2,3.5h0c-0.1,2.1-0.9,4.4-2.5,6c-1.6,1.6-3.4,2.4-5.5,2.5c-0.8,0-1.4,0.1-1.9,0.3 c-0.2,0.1-1,0.8-1.2,0.9C26.6,38,27,38.9,27,40c0,2.2-1.8,4-4,4s-4-1.8-4-4c0-1.5,0.8-2.7,2-3.4V23.4C19.8,22.7,19,21.4,19,20z"
/>
</g>
</svg>
Expand Down Expand Up @@ -249,12 +244,7 @@ exports[`<HierarchicalLocationsView /> displays multiple locations grouped by fi
d="M23,42.4c1.3,0,2.4-1.1,2.4-2.4s-1.1-2.4-2.4-2.4s-2.4,1.1-2.4,2.4S21.7,42.4,23,42.4z"
/>
<path
d="M50,16h-1.5c-0.3,0-0.5,0.2-0.5,0.5v35c0,0.3-0.2,0.5-0.5,0.5h-27c-0.5,0-1-0.2-1.4-0.6l-0.6-0.6c-0.1-0.1-0.1-0.2-0.1-0.4
c0-0.3,0.2-0.5,0.5-0.5H44c1.1,0,2-0.9,2-2V12c0-1.1-0.9-2-2-2H14c-1.1,0-2,0.9-2,2v36.3c0,1.1,0.4,2.1,1.2,2.8l3.1,3.1
c1.1,1.1,2.7,1.8,4.2,1.8H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.2-1.8,4-4,4s-4-1.8-4-4c0-1.5,0.8-2.7,2-3.4V23.4C19.8,22.7,19,21.4,19,20z"
/>
</g>
</svg>
Expand Down Expand Up @@ -417,12 +407,7 @@ exports[`<HierarchicalLocationsView /> displays partial locations before complet
d="M23,42.4c1.3,0,2.4-1.1,2.4-2.4s-1.1-2.4-2.4-2.4s-2.4,1.1-2.4,2.4S21.7,42.4,23,42.4z"
/>
<path
d="M50,16h-1.5c-0.3,0-0.5,0.2-0.5,0.5v35c0,0.3-0.2,0.5-0.5,0.5h-27c-0.5,0-1-0.2-1.4-0.6l-0.6-0.6c-0.1-0.1-0.1-0.2-0.1-0.4
c0-0.3,0.2-0.5,0.5-0.5H44c1.1,0,2-0.9,2-2V12c0-1.1-0.9-2-2-2H14c-1.1,0-2,0.9-2,2v36.3c0,1.1,0.4,2.1,1.2,2.8l3.1,3.1
c1.1,1.1,2.7,1.8,4.2,1.8H50c1.1,0,2-0.9,2-2V18C52,16.9,51.1,16,50,16z M19,20c0-2.2,1.8-4,4-4c1.4,0,2.8,0.8,3.5,2
c1.1,1.9,0.4,4.3-1.5,5.4V33c1-0.6,2.3-0.9,4-0.9c1,0,2-0.5,2.8-1.3C32.5,30,33,29.1,33,28v-0.6c-1.2-0.7-2-2-2-3.5
c0-2.2,1.8-4,4-4c2.2,0,4,1.8,4,4c0,1.5-0.8,2.7-2,3.5h0c-0.1,2.1-0.9,4.4-2.5,6c-1.6,1.6-3.4,2.4-5.5,2.5c-0.8,0-1.4,0.1-1.9,0.3
c-0.2,0.1-1,0.8-1.2,0.9C26.6,38,27,38.9,27,40c0,2.2-1.8,4-4,4s-4-1.8-4-4c0-1.5,0.8-2.7,2-3.4V23.4C19.8,22.7,19,21.4,19,20z"
d="M50,16h-1.5c-0.3,0-0.5,0.2-0.5,0.5v35c0,0.3-0.2,0.5-0.5,0.5h-27c-0.5,0-1-0.2-1.4-0.6l-0.6-0.6c-0.1-0.1-0.1-0.2-0.1-0.4 c0-0.3,0.2-0.5,0.5-0.5H44c1.1,0,2-0.9,2-2V12c0-1.1-0.9-2-2-2H14c-1.1,0-2,0.9-2,2v36.3c0,1.1,0.4,2.1,1.2,2.8l3.1,3.1 c1.1,1.1,2.7,1.8,4.2,1.8H50c1.1,0,2-0.9,2-2V18C52,16.9,51.1,16,50,16z M19,20c0-2.2,1.8-4,4-4c1.4,0,2.8,0.8,3.5,2 c1.1,1.9,0.4,4.3-1.5,5.4V33c1-0.6,2.3-0.9,4-0.9c1,0,2-0.5,2.8-1.3C32.5,30,33,29.1,33,28v-0.6c-1.2-0.7-2-2-2-3.5 c0-2.2,1.8-4,4-4c2.2,0,4,1.8,4,4c0,1.5-0.8,2.7-2,3.5h0c-0.1,2.1-0.9,4.4-2.5,6c-1.6,1.6-3.4,2.4-5.5,2.5c-0.8,0-1.4,0.1-1.9,0.3 c-0.2,0.1-1,0.8-1.2,0.9C26.6,38,27,38.9,27,40c0,2.2-1.8,4-4,4s-4-1.8-4-4c0-1.5,0.8-2.7,2-3.4V23.4C19.8,22.7,19,21.4,19,20z"
/>
</g>
</svg>
Expand Down

0 comments on commit da87d7f

Please sign in to comment.