ejected create-react-app
This commit is contained in:
14
config/jest/cssTransform.js
Normal file
14
config/jest/cssTransform.js
Normal file
@@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
// This is a custom Jest transformer turning style imports into empty objects.
|
||||
// http://facebook.github.io/jest/docs/tutorial-webpack.html
|
||||
|
||||
module.exports = {
|
||||
process() {
|
||||
return 'module.exports = {};';
|
||||
},
|
||||
getCacheKey() {
|
||||
// The output is always the same.
|
||||
return 'cssTransform';
|
||||
},
|
||||
};
|
||||
12
config/jest/fileTransform.js
Normal file
12
config/jest/fileTransform.js
Normal file
@@ -0,0 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
|
||||
// This is a custom Jest transformer turning file imports into filenames.
|
||||
// http://facebook.github.io/jest/docs/tutorial-webpack.html
|
||||
|
||||
module.exports = {
|
||||
process(src, filename) {
|
||||
return `module.exports = ${JSON.stringify(path.basename(filename))};`;
|
||||
},
|
||||
};
|
||||
35
config/jest/typescriptTransform.js
Normal file
35
config/jest/typescriptTransform.js
Normal file
@@ -0,0 +1,35 @@
|
||||
// Copyright 2004-present Facebook. All Rights Reserved.
|
||||
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const tsc = require('typescript');
|
||||
const tsconfigPath = require('app-root-path').resolve('/tsconfig.json');
|
||||
|
||||
let compilerConfig = {
|
||||
module: tsc.ModuleKind.CommonJS,
|
||||
jsx: tsc.JsxEmit.React,
|
||||
}
|
||||
|
||||
if (fs.existsSync(tsconfigPath)) {
|
||||
try {
|
||||
const tsconfig = require(tsconfigPath);
|
||||
|
||||
if (tsconfig && tsconfig.compilerOptions) {
|
||||
compilerConfig = tsconfig.compilerOptions;
|
||||
}
|
||||
} catch (e) { /* Do nothing - default is set */ }
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
process(src, path) {
|
||||
if (path.endsWith('.ts') || path.endsWith('.tsx')) {
|
||||
return tsc.transpile(
|
||||
src,
|
||||
compilerConfig,
|
||||
path, []
|
||||
);
|
||||
}
|
||||
return src;
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user