Skip to content

Commit

Permalink
test: update config (#925)
Browse files Browse the repository at this point in the history
* test: update config

* test(calendar): resove timezone problem

* test(calendar): resove timezone problem

* test(calendar): resove timezone problem

* test(input): update snapshot
  • Loading branch information
LeeJim authored Oct 18, 2022
1 parent ae1403b commit 20424ca
Show file tree
Hide file tree
Showing 105 changed files with 482 additions and 410 deletions.
5 changes: 1 addition & 4 deletions gen-demo-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ function getKeyFunction(component) {
describe('${newComponent}', () => {
mapper.forEach((demoName) => {
it(\`${newComponent} \${demoName} demo works fine\`, () => {
const id = simulate.load(path.resolve(__dirname, \`../../${component}/_example/\${demoName}/index\`), demoName, {
less: true,
rootPath: path.resolve(__dirname, '../..'),
});
const id = load(path.resolve(__dirname, \`../../${component}/_example/\${demoName}/index\`), demoName);
const container = simulate.render(id);
container.attach(document.createElement('parent-wrapper'));
expect(container.toJSON()).toMatchSnapshot();
Expand Down
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ module.exports = {
globals: {
CONFIG_PREFIX: 't',
},
globalSetup: '<rootDir>/script/test/globalSetup.js',
snapshotSerializers: ['miniprogram-simulate/jest-snapshot-plugin'],
};
3 changes: 3 additions & 0 deletions script/test/globalSetup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = async () => {
process.env.TZ = 'Asia/Shanghai';
};
12 changes: 12 additions & 0 deletions script/test/setup.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
import Path from 'path';
import simulate from 'miniprogram-simulate';

global.getApp = () => null;
global.Page = (options) => Component(options);
global.load = (path, demoName) => {
return simulate.load(path, demoName, {
less: true,
rootPath: Path.resolve(__dirname, '../../src'),
compilerOptions: {
maxBuffer: 1024 * (1024 + 100),
},
});
};
5 changes: 1 addition & 4 deletions src/action-sheet/__test__/demo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ const mapper = ['grid', 'grid-multi', 'icon-list', 'list'];
describe('ActionSheet', () => {
mapper.forEach((demoName) => {
it(`ActionSheet ${demoName} demo works fine`, () => {
const id = simulate.load(path.resolve(__dirname, `../../action-sheet/_example/${demoName}/index`), demoName, {
less: true,
rootPath: path.resolve(__dirname, '../..'),
});
const id = load(path.resolve(__dirname, `../../action-sheet/_example/${demoName}/index`), demoName);
const container = simulate.render(id);
container.attach(document.createElement('parent-wrapper'));
expect(container.toJSON()).toMatchSnapshot();
Expand Down
5 changes: 1 addition & 4 deletions src/action-sheet/__test__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ describe('action-sheet', () => {
Grid: 'grid',
};

const actionSheet = simulate.load(path.resolve(__dirname, `../action-sheet`), 't-action-sheet', {
less: true,
rootPath: path.resolve(__dirname, '../..'),
});
const actionSheet = load(path.resolve(__dirname, `../action-sheet`), 't-action-sheet');

describe('props', () => {
it(': cancel-text', async () => {
Expand Down
5 changes: 1 addition & 4 deletions src/avatar/__test__/demo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ const mapper = ['action', 'exhibition', 'shape', 'size'];
describe('Avatar', () => {
mapper.forEach((demoName) => {
it(`Avatar ${demoName} demo works fine`, () => {
const id = simulate.load(path.resolve(__dirname, `../../avatar/_example/${demoName}/index`), demoName, {
less: true,
rootPath: path.resolve(__dirname, '../..'),
});
const id = load(path.resolve(__dirname, `../../avatar/_example/${demoName}/index`), demoName);
const container = simulate.render(id);
container.attach(document.createElement('parent-wrapper'));
expect(container.toJSON()).toMatchSnapshot();
Expand Down
5 changes: 1 addition & 4 deletions src/avatar/__test__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import simulate from 'miniprogram-simulate';
import path from 'path';

describe('Avatar & Avatar Groups', () => {
const id = simulate.load(path.resolve(__dirname, './index'), {
less: true,
rootPath: path.resolve(__dirname, '../..'),
});
const id = load(path.resolve(__dirname, './index'));

describe('Avatar Props', () => {
it(':icon', () => {
Expand Down
5 changes: 1 addition & 4 deletions src/back-top/__test__/demo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ const mapper = ['base'];
describe('BackTop', () => {
mapper.forEach((demoName) => {
it(`BackTop ${demoName} demo works fine`, () => {
const id = simulate.load(path.resolve(__dirname, `../../back-top/_example/${demoName}/index`), demoName, {
less: true,
rootPath: path.resolve(__dirname, '../..'),
});
const id = load(path.resolve(__dirname, `../../back-top/_example/${demoName}/index`), demoName);
const container = simulate.render(id);
container.attach(document.createElement('parent-wrapper'));
expect(container.toJSON()).toMatchSnapshot();
Expand Down
5 changes: 1 addition & 4 deletions src/badge/__test__/demo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ const mapper = ['base', 'button', 'cell', 'tab-item'];
describe('Badge', () => {
mapper.forEach((demoName) => {
it(`Badge ${demoName} demo works fine`, () => {
const id = simulate.load(path.resolve(__dirname, `../../badge/_example/${demoName}/index`), demoName, {
less: true,
rootPath: path.resolve(__dirname, '../..'),
});
const id = load(path.resolve(__dirname, `../../badge/_example/${demoName}/index`), demoName);
const container = simulate.render(id);
container.attach(document.createElement('parent-wrapper'));
expect(container.toJSON()).toMatchSnapshot();
Expand Down
5 changes: 1 addition & 4 deletions src/badge/__test__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ const shapes = ['circle', 'square', 'round', 'ribbon'];
const sizes = ['small', 'medium'];

describe('badge', () => {
const badge = simulate.load(path.resolve(__dirname, `../badge`), 't-badge', {
less: true,
rootPath: path.resolve(__dirname, '../..'),
});
const badge = load(path.resolve(__dirname, `../badge`), 't-badge');

it(`:base`, () => {
const id = simulate.load({
Expand Down
5 changes: 1 addition & 4 deletions src/button/__test__/demo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ const mapper = ['base', 'icon-btn', 'size'];
describe('Button', () => {
mapper.forEach((demoName) => {
it(`Button ${demoName} demo works fine`, () => {
const id = simulate.load(path.resolve(__dirname, `../../button/_example/${demoName}/index`), demoName, {
less: true,
rootPath: path.resolve(__dirname, '../..'),
});
const id = load(path.resolve(__dirname, `../../button/_example/${demoName}/index`), demoName);
const container = simulate.render(id);
container.attach(document.createElement('parent-wrapper'));
expect(container.toJSON()).toMatchSnapshot();
Expand Down
8 changes: 2 additions & 6 deletions src/button/__test__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ import simulate from 'miniprogram-simulate';
import path from 'path';

describe('button', () => {
const options = {
less: true,
rootPath: path.resolve(__dirname, '../..'),
};
const button = simulate.load(path.resolve(__dirname, '../button'), options);
const button = load(path.resolve(__dirname, '../button'));

it(`:base`, async () => {
const id = simulate.load({
Expand Down Expand Up @@ -93,7 +89,7 @@ describe('button', () => {
});

it(':with group', () => {
const buttonGroup = simulate.load(path.resolve(__dirname, '../../button-group/button-group'), options);
const buttonGroup = load(path.resolve(__dirname, '../../button-group/button-group'));
const id = simulate.load({
template: `<t-button-group type="primary" class="button-group">
<t-button></t-button>
Expand Down
80 changes: 80 additions & 0 deletions src/calendar/__test__/__snapshots__/demo.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Calendar Calendar base demo works fine 1`] = `
<base>
<t-calendar
visible="{{false}}"
bind:confirm="handleConfirm"
/>
<t-cell
arrow="{{true}}"
title="单个选择日历"
bind:tap="handleCalendar"
/>
</base>
`;

exports[`Calendar Calendar custom-range demo works fine 1`] = `
<custom-range>
<t-calendar
maxDate="{{1645891200000}}"
minDate="{{1643644800000}}"
value="{{1644854400000}}"
visible="{{false}}"
bind:confirm="handleConfirm"
/>
<t-cell
arrow="{{true}}"
title="自定义区间"
bind:tap="handleCalendar"
/>
</custom-range>
`;

exports[`Calendar Calendar custom-text demo works fine 1`] = `
<custom-text>
<t-calendar
format="{{[Function]}}"
maxDate="{{1647273600000}}"
minDate="{{1643644800000}}"
value="{{1644854400000}}"
visible="{{false}}"
bind:confirm="handleConfirm"
/>
<t-cell
arrow="{{true}}"
title="自定义文案"
bind:tap="handleCalendar"
/>
</custom-text>
`;

exports[`Calendar Calendar multiple demo works fine 1`] = `
<multiple>
<t-calendar
type="multiple"
visible="{{false}}"
bind:confirm="handleConfirm"
/>
<t-cell
arrow="{{true}}"
title="多个选择日历"
bind:tap="handleCalendar"
/>
</multiple>
`;

exports[`Calendar Calendar range demo works fine 1`] = `
<range>
<t-calendar
type="range"
visible="{{false}}"
bind:confirm="handleConfirm"
/>
<t-cell
arrow="{{true}}"
title="区间选择日历"
bind:tap="handleCalendar"
/>
</range>
`;
19 changes: 19 additions & 0 deletions src/calendar/__test__/demo.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* 该文件为由脚本 `npm run test:demo` 自动生成,如需修改,执行脚本命令即可。请勿手写直接修改,否则会被覆盖
*/

import simulate from 'miniprogram-simulate';
import path from 'path';

const mapper = ['base', 'custom-range', 'custom-text', 'multiple', 'range'];

describe('Calendar', () => {
mapper.forEach((demoName) => {
it(`Calendar ${demoName} demo works fine`, () => {
const id = load(path.resolve(__dirname, `../../calendar/_example/${demoName}/index`), demoName);
const container = simulate.render(id);
container.attach(document.createElement('parent-wrapper'));
expect(container.toJSON()).toMatchSnapshot();
});
});
});
5 changes: 1 addition & 4 deletions src/calendar/__test__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import simulate from 'miniprogram-simulate';
import path from 'path';

describe('calendar', () => {
const calendar = simulate.load(path.resolve(__dirname, `../calendar`), 't-calendar', {
less: true,
rootPath: path.resolve(__dirname, '../..'),
});
const calendar = load(path.resolve(__dirname, `../calendar`), 't-calendar');

it(':base', () => {
const id = simulate.load({
Expand Down
Loading

0 comments on commit 20424ca

Please sign in to comment.