Commit 3c53cf5e authored by Sendya's avatar Sendya

fix: jest

parent 8fea1d73
...@@ -2,28 +2,36 @@ const libDir = process.env.LIB_DIR; ...@@ -2,28 +2,36 @@ const libDir = process.env.LIB_DIR;
const transformIgnorePatterns = [ const transformIgnorePatterns = [
'/dist/', '/dist/',
'node_modules/[^/]+?/(?!(node_modules)/)', // Ignore modules without es dir // Ignore modules without es dir.
// Update: @babel/runtime should also be transformed
'node_modules/(?!.*(@babel|lodash-es))[^/]+?/(?!(es|node_modules)/)',
]; ];
const testPathIgnorePatterns = ['/node_modules/', 'node'];
module.exports = { module.exports = {
testURL: 'http://localhost/', testURL: 'http://localhost/',
preset: 'ts-jest', preset: 'ts-jest',
moduleFileExtensions: ['js', 'ts', 'tsx', 'json', 'vue'], moduleFileExtensions: ['js', 'ts', 'tsx', 'json', 'vue'],
modulePathIgnorePatterns: ['/_site/'], modulePathIgnorePatterns: ['/_site/'],
testPathIgnorePatterns: ['/node_modules/', 'node'],
transform: { transform: {
'.*\\.(vue)$': '<rootDir>/node_modules/vue-jest', '.*\\.(vue)$': '<rootDir>/node_modules/vue-jest',
'^.+\\.(ts|tsx)$': '<rootDir>/node_modules/babel-jest', '^.+\\.(js|jsx)$': '<rootDir>/node_modules/babel-jest',
'^.+\\.(ts|tsx)$': '<rootDir>/node_modules/ts-jest',
'.+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$': 'jest-transform-stub', '.+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$': 'jest-transform-stub',
}, },
testRegex: libDir === 'dist' ? 'demo\\.test\\.ts$' : '.*\\.test\\.tsx$', testRegex: libDir === 'dist' ? 'demo\\.test\\.ts$' : '.*\\.test\\.tsx$',
testEnvironment: 'node', testEnvironment: 'jest-environment-jsdom-fifteen',
moduleNameMapper: { moduleNameMapper: {
'^@/(.*)$': '<rootDir>/$1', '^@/(.*)$': '<rootDir>/$1',
}, },
snapshotSerializers: ['<rootDir>/node_modules/jest-serializer-vue'], snapshotSerializers: ['<rootDir>/node_modules/jest-serializer-vue'],
collectCoverage: process.env.COVERAGE === 'true', collectCoverage: process.env.COVERAGE === 'true',
collectCoverageFrom: ['src/**/*.{ts,tsx,vue}'], collectCoverageFrom: ['src/**/*.{ts,tsx,vue}'],
testPathIgnorePatterns,
transformIgnorePatterns, transformIgnorePatterns,
verbose: true, verbose: true,
globals: {
'ts-jest': {
babelConfig: true,
},
},
}; };
...@@ -18,10 +18,9 @@ ...@@ -18,10 +18,9 @@
"start": "vc-tools run server", "start": "vc-tools run server",
"lint": "eslint src/ -c .eslintrc.js --ext .tsx,.ts", "lint": "eslint src/ -c .eslintrc.js --ext .tsx,.ts",
"lint:fix": "eslint --fix src/ -c .eslintrc.js --ext .tsx,.ts", "lint:fix": "eslint --fix src/ -c .eslintrc.js --ext .tsx,.ts",
"compile": "cross-env TS_NODE_PROJECT=scripts/tsconfig.json vc-tools run compile", "compile": "vc-tools run compile",
"test": "cross-env NODE_ENV=test jest --config .jest.js", "test": "cross-env NODE_ENV=test jest --config .jest.js",
"prepublishOnly": "npm run lint && npm run compile && npm run test", "prepublishOnly": "npm run lint && npm run compile && npm run test"
"postcompile": "npm run clean"
}, },
"peerDependencies": { "peerDependencies": {
"ant-design-vue": ">=2.0.0", "ant-design-vue": ">=2.0.0",
...@@ -51,10 +50,12 @@ ...@@ -51,10 +50,12 @@
"eslint-plugin-vue": "^7.0.0-0", "eslint-plugin-vue": "^7.0.0-0",
"fs-extra": "^9.0.1", "fs-extra": "^9.0.1",
"jest": "^25.4.0", "jest": "^25.4.0",
"jest-environment-jsdom-fifteen": "^1.0.2",
"jest-serializer-vue": "^2.0.2", "jest-serializer-vue": "^2.0.2",
"jest-transform-stub": "^2.0.0", "jest-transform-stub": "^2.0.0",
"prettier": "^1.19.1", "prettier": "^1.19.1",
"rimraf": "^3.0.2", "rimraf": "^3.0.2",
"ts-jest": "^26.4.4",
"ts-node": "^8.10.2", "ts-node": "^8.10.2",
"typescript": "~3.9.3", "typescript": "~3.9.3",
"vue": "^3.0.0-0", "vue": "^3.0.0-0",
......
const rimraf = require('rimraf'); import rimraf from 'rimraf';
const path = require('path'); import path from 'path';
const errorHandler = (err) => { const errorHandler = err => {
console.error('err', err); if (err !== null) {
} console.warn(err);
}
};
rimraf(path.resolve(__dirname, 'es'), errorHandler); rimraf(path.resolve(__dirname, '../es'), errorHandler);
rimraf(path.resolve(__dirname, 'lib'), errorHandler); rimraf(path.resolve(__dirname, '../lib'), errorHandler);
{ {
"compilerOptions": { "compilerOptions": {
"allowSyntheticDefaultImports": true, "module": "commonJS",
"declaration": true,
"module": "esnext",
"target": "esnext",
"moduleResolution": "node",
"jsx": "preserve",
"esModuleInterop": true "esModuleInterop": true
}, }
"include": ["./src", "./typings/"], }
"typings": "./typings/index.d.ts", \ No newline at end of file
"exclude": [
"node_modules",
"build",
"scripts",
"acceptance-tests",
"webpack",
"jest",
"src/setupTests.ts",
"tslint:latest",
"tslint-config-prettier"
]
}
...@@ -10,10 +10,9 @@ export interface GridContentProps { ...@@ -10,10 +10,9 @@ export interface GridContentProps {
} }
const GridContent: FunctionalComponent<GridContentProps> = (props, { slots }) => { const GridContent: FunctionalComponent<GridContentProps> = (props, { slots }) => {
const proConfig = useProProvider(); const { contentWidth, getPrefixCls } = useProProvider();
const { contentWidth, getPrefixCls } = toRefs(proConfig); const customPrefixCls = props.prefixCls || getPrefixCls();
const customPrefixCls = props.prefixCls || getPrefixCls.value(); const customContentWidth = props.contentWidth || contentWidth;
const customContentWidth = props.contentWidth || contentWidth.value;
return ( return (
<div <div
class={{ class={{
......
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`GridContent shoul render with empty children 1`] = `
<div class="ant-pro-grid-content">
<div class="ant-pro-grid-content-children">
<!---->
</div>
</div>
`;
import { mount } from '@vue/test-utils';
import GridContent from '../src/GridContent';
describe('GridContent', () => {
it('shoul render with empty children', () => {
const wrapper = mount(GridContent, { });
expect(wrapper.html()).toMatchSnapshot();
});
it('shoul render with prop Fixed', () => {
const wrapper = mount({
setup() {
return () => (
<GridContent contentWidth="Fixed"></GridContent>
);
},
});
expect(wrapper.classes().indexOf('wide') > -1).toBe(true);
});
it('shoul render with children', () => {
const wrapper = mount({
setup() {
return () => (
<GridContent contentWidth="Fixed">
<div>children</div>
</GridContent>
);
},
});
expect(wrapper.find('.ant-pro-grid-content-children').element.innerHTML === '<div>children</div>').toBe(true);
});
});
import { mount } from '@vue/test-utils'; import { mount } from '@vue/test-utils';
// import BasicLayout from '../src/BasicLayout';
describe('index', () => { describe('BasicLayout', () => {
it('shoul render GridContent', () => { it('🥩 base use', () => {
// empty // const wrapper = mount(BasicLayout, { });
// console.log(wrapper.html());
// expect(wrapper.html()).toMatchSnapshot();
}); });
}); });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment