Skip to content

Commit

Permalink
setup test environment
Browse files Browse the repository at this point in the history
  • Loading branch information
yfxie committed Mar 26, 2019
1 parent bb8a9dc commit f15fe9c
Show file tree
Hide file tree
Showing 5 changed files with 457 additions and 139 deletions.
8 changes: 8 additions & 0 deletions __tests__/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const path = require('path');

process.argv = ['', ''];
process.env.JEKPACK_TEST = true;
process.env.JEKPACK_TEST_CWD = path.resolve(__dirname, 'tmp');
process.env.JEKPACK_ROOT = path.resolve(__dirname, '..');
process.env.JEKPACK_BIN_PATH = require.resolve(path.resolve(process.env.JEKPACK_ROOT, 'bin'));

17 changes: 16 additions & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,19 @@ const presets = [
],
];

module.exports = { presets };
const testPresets = [
[
'@babel/preset-env',
{
targets: {
node: 'current',
},
},
],
];

module.exports = api => {
const isTest = api.env('test');
const presets = isTest ? testPresets : presets;
return { presets };
};
23 changes: 11 additions & 12 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ module.exports = {
// collectCoverage: false,

// An array of glob patterns indicating a set of files for which coverage information should be collected
// collectCoverageFrom: null,
collectCoverageFrom: [
"{bin,lib,generator}/**/*.js",
],

// The directory where Jest should output its coverage files
coverageDirectory: "coverage",
Expand All @@ -33,10 +35,7 @@ module.exports = {

// A list of reporter names that Jest uses when writing coverage reports
// coverageReporters: [
// "json",
// "text",
// "lcov",
// "clover"
// "none",
// ],

// An object that configures minimum threshold enforcement for coverage results
Expand All @@ -62,8 +61,9 @@ module.exports = {

// An array of directory names to be searched recursively up from the requiring module's location
moduleDirectories: [
"<rootDir>",
"node_modules",
"__tests__"
"__tests__/test-utils",
],

// An array of file extensions your modules use
Expand Down Expand Up @@ -121,7 +121,7 @@ module.exports = {
// runner: "jest-runner",

// The paths to modules that run some code to configure or set up the testing environment before each test
// setupFiles: [],
setupFiles: ['<rootDir>/__tests__/setup.js'],

// A list of paths to modules that run some code to configure or set up the testing framework before each test
// setupFilesAfterEnv: [],
Expand All @@ -139,10 +139,9 @@ module.exports = {
// testLocationInResults: false,

// The glob patterns Jest uses to detect test files
// testMatch: [
// "**/__tests__/**/*.[jt]s?(x)",
// "**/?(*.)+(spec|test).[tj]s?(x)"
// ],
testMatch: [
"**/?(*.)+(spec|test).[jt]s?(x)"
],

// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
// testPathIgnorePatterns: [
Expand All @@ -165,7 +164,7 @@ module.exports = {
// timers: "real",

// A map from regular expressions to paths to transformers
// transform: null,
// transform: {},

// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
// transformIgnorePatterns: [
Expand Down
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
"version": "1.0.1",
"devDependencies": {
"@babel/cli": "^7.2.3",
"@babel/core": "^7.3.4",
"@babel/preset-env": "^7.3.4",
"@babel/core": "^7.4.0",
"@babel/preset-env": "^7.4.2",
"autoprefixer": "^9.4.10",
"aws-sdk": "^2.425.0",
"babel-jest": "^24.5.0",
"babel-loader": "^8.0.5",
"chalk": "^2.4.2",
"commander": "^2.19.0",
Expand All @@ -19,13 +20,16 @@
"file-loader": "^3.0.1",
"fs-extra": "^7.0.1",
"globby": "^9.1.0",
"inquirer": "^6.2.2",
"jest": "^24.5.0",
"mini-css-extract-plugin": "^0.5.0",
"node-sass": "^4.11.0",
"nodemon": "^1.18.10",
"nyc": "^13.3.0",
"optimize-css-assets-webpack-plugin": "^5.0.1",
"ora": "^3.2.0",
"postcss-loader": "^3.0.0",
"puppeteer": "^1.13.0",
"rimraf": "^2.6.3",
"s3-easy-deploy": "^1.1.0",
"sass-loader": "^7.1.0",
Expand All @@ -44,7 +48,7 @@
"dev": "concurrently npm:dev-*",
"build": "node config/webpack/build.js",
"release": "standard-version",
"test": "jest"
"test": "jest --coverage"
},
"license": "MIT"
}
Loading

0 comments on commit f15fe9c

Please sign in to comment.