diff --git a/.jest.js b/.jest.js new file mode 100644 index 0000000000..9b807b86af --- /dev/null +++ b/.jest.js @@ -0,0 +1,48 @@ +const libDir = process.env.LIB_DIR; + +const transformIgnorePatterns = [ + '/dist/', + '/node_modules/reqwest', +]; + +if (libDir !== 'es') { + transformIgnorePatterns.push('/node_modules/'); +} + +module.exports = { + setupFiles: [ + './tests/setup.js', + ], + moduleFileExtensions: [ + 'ts', + 'tsx', + 'js', + 'jsx', + 'json', + 'md', + ], + modulePathIgnorePatterns: [ + '/_site/', + ], + testPathIgnorePatterns: [ + '/node_modules/', + 'dekko', + 'node', + ], + transform: { + '\\.tsx?$': './node_modules/typescript-babel-jest', + '\\.js$': './node_modules/babel-jest', + '\\.md$': './node_modules/antd-demo-jest', + }, + testRegex: libDir ? 'demo\\.test\\.js$' : '.*\\.test\\.js$', + collectCoverageFrom: [ + 'components/**/*.{ts,tsx}', + '!components/*/style/index.tsx', + '!components/style/index.tsx', + '!components/*/locale/index.tsx', + ], + transformIgnorePatterns, + snapshotSerializers: [ + 'enzyme-to-json/serializer', + ], +}; diff --git a/.jest.node.js b/.jest.node.js new file mode 100644 index 0000000000..43dc85659a --- /dev/null +++ b/.jest.node.js @@ -0,0 +1,21 @@ +module.exports = { + setupFiles: [ + './tests/setup.js', + ], + moduleFileExtensions: [ + 'ts', + 'tsx', + 'js', + 'md', + ], + transform: { + '\\.tsx?$': './node_modules/typescript-babel-jest', + '\\.js$': './node_modules/babel-jest', + '\\.md$': './node_modules/antd-demo-jest', + }, + testRegex: 'demo\\.test\\.js$', + testEnvironment: 'node', + snapshotSerializers: [ + 'enzyme-to-json/serializer' + ], +}; diff --git a/.jest.node.json b/.jest.node.json deleted file mode 100644 index 573bcce851..0000000000 --- a/.jest.node.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "setupFiles": [ - "./tests/setup.js" - ], - "moduleFileExtensions": [ - "ts", - "tsx", - "js", - "md" - ], - "transform": { - "\\.tsx?$": "./node_modules/typescript-babel-jest", - "\\.js$": "./node_modules/babel-jest", - "\\.md$": "./node_modules/antd-demo-jest" - }, - "testRegex": "demo\\.test\\.js$", - "testEnvironment": "node", - "snapshotSerializers": ["enzyme-to-json/serializer"] -} diff --git a/.travis.yml b/.travis.yml index d1049a9195..d61b9b97eb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,13 +20,16 @@ script: elif [ "$TEST_TYPE" = dist ]; then npm run dist && \ node ./tests/dekko/dist.test.js + LIB_DIR=dist npm test -- --coverage -w 2 elif [ "$TEST_TYPE" = compile ]; then npm run compile && \ node ./tests/dekko/lib.test.js + LIB_DIR=es npm test -- --coverage -w 2 + LIB_DIR=lib npm test -- --coverage -w 2 elif [ "$TEST_TYPE" = test:dom ]; then npm run dist && \ npm test -- --coverage -w 2 && \ bash <(curl -s https://codecov.io/bash) elif [ "$TEST_TYPE" = test:node ]; then - npm test -- --config .jest.node.json -w 2 + npm run test-node -- -w 2 fi diff --git a/package.json b/package.json index 215a347bad..20258bfb98 100644 --- a/package.json +++ b/package.json @@ -81,7 +81,7 @@ "devDependencies": { "@types/react": "^15.0.8", "@types/react-dom": "~0.14.18", - "antd-demo-jest": "^1.0.5", + "antd-demo-jest": "^1.3.0", "antd-tools": "~1.5.0", "babel-cli": "^6.18.0", "babel-eslint": "^7.1.0", @@ -116,7 +116,7 @@ "eslint-tinker": "^0.4.0", "fetch-jsonp": "^1.0.3", "glob": "^7.1.1", - "jest": "^19.0.2", + "jest": "^20.0.4", "jsonml.js": "^0.1.0", "lint-staged": "^3.3.1", "mockdate": "^2.0.1", @@ -145,7 +145,8 @@ "xhr2": "^0.1.3" }, "scripts": { - "test": "jest", + "test": "jest --config .jest.js", + "test-node": "jest --config .jest.node.js", "test-all": "./scripts/test-all.sh", "lint": "npm run lint:ts && npm run lint:es && npm run lint:demo && npm run lint:style", "lint:ts": "npm run tsc && antd-tools run ts-lint", @@ -183,46 +184,6 @@ "lint-staged:demo" ] }, - "jest": { - "setupFiles": [ - "./tests/setup.js" - ], - "moduleFileExtensions": [ - "ts", - "tsx", - "js", - "jsx", - "json", - "md" - ], - "modulePathIgnorePatterns": [ - "/_site/" - ], - "testPathIgnorePatterns": [ - "/node_modules/", - "dekko", - "node" - ], - "transform": { - "\\.tsx?$": "./node_modules/typescript-babel-jest", - "\\.js$": "./node_modules/babel-jest", - "\\.md$": "./node_modules/antd-demo-jest" - }, - "testRegex": ".*\\.test\\.js$", - "collectCoverageFrom": [ - "components/**/*.{ts,tsx}", - "!components/*/style/index.tsx", - "!components/style/index.tsx", - "!components/*/locale/index.tsx" - ], - "transformIgnorePatterns": [ - "/node_modules/", - "/dist/" - ], - "snapshotSerializers": [ - "enzyme-to-json/serializer" - ] - }, "pre-commit": [ "lint-staged" ] diff --git a/scripts/test-all.sh b/scripts/test-all.sh index c6bef37ae0..33c1780fb9 100755 --- a/scripts/test-all.sh +++ b/scripts/test-all.sh @@ -3,7 +3,10 @@ npm run lint && \ npm run dist && \ node ./tests/dekko/dist.test.js && \ +LIB_DIR=dist npm test && \ npm run compile && \ node ./tests/dekko/lib.test.js && \ -npm test -- --coverage -w $MAX_WORKERS && \ -npm test -- --config .jest.node.json -w $MAX_WORKERS +LIB_DIR=es npm test && \ +LIB_DIR=lib npm test && \ +npm test && \ +npm run test-node