Skip to content

Commit

Permalink
test(exoflex): make tests even FASTER, BLAZING FAST ⚡️ ⚡️ ⚡️ (#176)
Browse files Browse the repository at this point in the history
* test(exoflex): remove ts-jest; add @babel/typescript, patch-package

* test(exoflex): patch @jest/transformer
  • Loading branch information
oshimayoan committed Nov 6, 2019
1 parent 7db36c5 commit c174299
Show file tree
Hide file tree
Showing 5 changed files with 301 additions and 70 deletions.
2 changes: 1 addition & 1 deletion packages/exoflex/babel.config.js
@@ -1,3 +1,3 @@
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
presets: ['module:metro-react-native-babel-preset', '@babel/typescript'],
};
12 changes: 0 additions & 12 deletions packages/exoflex/jest.config.js
@@ -1,18 +1,6 @@
const { defaults: tsjPreset } = require('ts-jest/presets');

module.exports = {
...tsjPreset,
setupFiles: ['<rootDir>/test/modules-mock'],
preset: './jestPresets/jest-preset',
transform: {
...tsjPreset.transform,
'\\.js$': '<rootDir>/node_modules/react-native/jest/preprocessor.js',
},
globals: {
'ts-jest': {
babelConfig: true,
},
},
modulePathIgnorePatterns: ['<rootDir>/lib/', '<rootDir>/example/'],
transformIgnorePatterns: [
'node_modules/(?!(react-native|react-native-paper|react-native-safe-area-view|react-native-animation-hooks|react-native-svg|react-native-calendars|react-native-multi-slider|react-native-collapsible|react-native-modal-datetime-picker|react-native-vector-icons)/)',
Expand Down
7 changes: 5 additions & 2 deletions packages/exoflex/package.json
Expand Up @@ -18,7 +18,8 @@
"lint": "eslint --max-warnings 0 \"src/**/*.{ts,tsx}\"",
"typecheck": "tsc --noEmit -p .",
"jest": "jest --coverage --passWithNoTests",
"test": "yarn format:check && yarn lint && yarn typecheck && yarn jest"
"test": "yarn format:check && yarn lint && yarn typecheck && yarn jest",
"postinstall": "patch-package"
},
"peerDependencies": {
"expo-font": "*",
Expand All @@ -36,6 +37,7 @@
"react-native-paper": "^2.16.0"
},
"devDependencies": {
"@babel/preset-typescript": "^7.6.0",
"@react-native-community/bob": "^0.6.1",
"@testing-library/react": "^9.1.1",
"@testing-library/react-hooks": "^2.0.3",
Expand All @@ -59,6 +61,8 @@
"jest-watch-select-projects": "^1.0.0",
"jest-watch-typeahead": "^0.4.0",
"jest-with-platform": "^0.0.3",
"patch-package": "^6.2.0",
"postinstall-postinstall": "^2.0.0",
"prettier": "^1.18.2",
"react": "^16.9.0",
"react-dom": "^16.9.0",
Expand All @@ -70,7 +74,6 @@
"react-test-renderer": "^16.9.0",
"regenerator-runtime": "^0.13.3",
"release-it": "^12.3.6",
"ts-jest": "^24.0.2",
"typescript": "^3.5.3"
},
"@react-native-community/bob": {
Expand Down
34 changes: 34 additions & 0 deletions packages/exoflex/patches/@jest+transform+24.9.0.patch
@@ -0,0 +1,34 @@
diff --git a/node_modules/@jest/transform/build/ScriptTransformer.js b/node_modules/@jest/transform/build/ScriptTransformer.js
index 0dbc1d7..b595ec6 100644
--- a/node_modules/@jest/transform/build/ScriptTransformer.js
+++ b/node_modules/@jest/transform/build/ScriptTransformer.js
@@ -207,7 +207,7 @@ const _require = require('../package.json'),
// we need to transform a file. Since ScriptTransformer is instantiated for each
// file we need to keep this object in the local scope of this module.

-const projectCaches = new WeakMap(); // To reset the cache for specific changesets (rather than package version).
+const projectCaches = new Map(); // To reset the cache for specific changesets (rather than package version).

const CACHE_VERSION = '1';

@@ -239,16 +239,17 @@ class ScriptTransformer {
this._config = config;
this._transformCache = new Map();
this._transformConfigCache = new Map();
- let projectCache = projectCaches.get(config);
+ const configString = (0, _fastJsonStableStringify().default)(this._config);
+ let projectCache = projectCaches.get(configString);

if (!projectCache) {
projectCache = {
- configString: (0, _fastJsonStableStringify().default)(this._config),
+ configString,
ignorePatternsRegExp: calcIgnorePatternRegExp(this._config),
transformRegExp: calcTransformRegExp(this._config),
transformedFiles: new Map()
};
- projectCaches.set(config, projectCache);
+ projectCaches.set(configString, projectCache);
}

this._cache = projectCache;

0 comments on commit c174299

Please sign in to comment.