Skip to content

Commit

Permalink
refactor: ts配置调整
Browse files Browse the repository at this point in the history
  • Loading branch information
caijf committed May 11, 2023
1 parent 6b7e58b commit fc24da9
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 52 deletions.
3 changes: 0 additions & 3 deletions babel.config.js

This file was deleted.

5 changes: 5 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node'
};
7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@
},
"homepage": "https://github.com/caijf/pull2#readme",
"devDependencies": {
"@babel/core": "^7.19.3",
"@babel/preset-env": "^7.19.4",
"@babel/preset-typescript": "^7.18.6",
"@commitlint/cli": "^17.1.2",
"@commitlint/config-conventional": "^17.1.0",
"@parcel/transformer-less": "2.7.0",
Expand All @@ -72,10 +69,10 @@
"@typescript-eslint/eslint-plugin": "^5.40.1",
"@typescript-eslint/parser": "^5.40.1",
"autoprefixer": "^10.4.12",
"babel-jest": "^29.2.1",
"cz-conventional-changelog": "^3.3.0",
"eslint": "^8.25.0",
"jest": "^29.2.0",
"ts-jest": "^29.1.0",
"jest-environment-jsdom": "^29.2.0",
"less": "^4.1.3",
"lint-staged": "^13.0.3",
Expand Down Expand Up @@ -111,4 +108,4 @@
"dependencies": {
"tslib": "^2.4.0"
}
}
}
4 changes: 3 additions & 1 deletion rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ export const commonConfig = {
plugins: [
resolve(),
commonjs(),
typescript({ include: ['src/**/*'] }),
typescript({
tsconfig: './tsconfig.build.json'
}),
postcss({
inject: true,
plugins: [autoprefixer]
Expand Down
84 changes: 42 additions & 42 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,23 @@ describe('PullToRefresh', () => {
expect(document.body.innerHTML).toMatchSnapshot();
expect(fn).toHaveBeenCalledTimes(0);

pullToRefreshInstance.triggerRefresh();
const p = pullToRefreshInstance.triggerRefresh();

// loding
expect(document.body.innerHTML).toMatchSnapshot();
expect(fn).toHaveBeenCalledTimes(1);

await fn();
await p;

// failed
expect(document.body.innerHTML).toMatchSnapshot();
expect(fn).toHaveBeenCalledTimes(2);
expect(fn).toHaveBeenCalledTimes(1);

pullToRefreshInstance.triggerRefresh();
await fn();
await pullToRefreshInstance.triggerRefresh();

// success
expect(document.body.innerHTML).toMatchSnapshot();
expect(fn).toHaveBeenCalledTimes(4);
expect(fn).toHaveBeenCalledTimes(2);
});

it('render define', async () => {
Expand Down Expand Up @@ -71,24 +70,23 @@ describe('PullToRefresh', () => {
expect(document.body.innerHTML).toMatchSnapshot();
expect(fn).toHaveBeenCalledTimes(0);

pullToRefreshInstance.triggerRefresh();
const p = pullToRefreshInstance.triggerRefresh();

// loding
expect(document.body.innerHTML).toMatchSnapshot();
expect(fn).toHaveBeenCalledTimes(1);

await fn();
await p;

// failed
expect(document.body.innerHTML).toMatchSnapshot();
expect(fn).toHaveBeenCalledTimes(2);
expect(fn).toHaveBeenCalledTimes(1);

pullToRefreshInstance.triggerRefresh();
await fn();
await pullToRefreshInstance.triggerRefresh();

// success
expect(document.body.innerHTML).toMatchSnapshot();
expect(fn).toHaveBeenCalledTimes(4);
expect(fn).toHaveBeenCalledTimes(2);
});

it('render update', async () => {
Expand Down Expand Up @@ -122,24 +120,23 @@ describe('PullToRefresh', () => {
expect(document.body.innerHTML).toMatchSnapshot();
expect(fn).toHaveBeenCalledTimes(0);

pullToRefreshInstance.triggerRefresh();
const p = pullToRefreshInstance.triggerRefresh();

// loding
expect(document.body.innerHTML).toMatchSnapshot();
expect(fn).toHaveBeenCalledTimes(1);

await fn();
await p;

// failed
expect(document.body.innerHTML).toMatchSnapshot();
expect(fn).toHaveBeenCalledTimes(2);
expect(fn).toHaveBeenCalledTimes(1);

pullToRefreshInstance.triggerRefresh();
await fn();
await pullToRefreshInstance.triggerRefresh();

// success
expect(document.body.innerHTML).toMatchSnapshot();
expect(fn).toHaveBeenCalledTimes(4);
expect(fn).toHaveBeenCalledTimes(2);
});

it('destroy & resume', async () => {
Expand All @@ -162,17 +159,17 @@ describe('PullToRefresh', () => {

// resume
pullToRefreshInstance.resume();
pullToRefreshInstance.triggerRefresh();
const p = pullToRefreshInstance.triggerRefresh();

// loading
expect(document.body.innerHTML).toMatchSnapshot();
expect(fn).toHaveBeenCalledTimes(1);

await fn();
await p;

// success
expect(document.body.innerHTML).toMatchSnapshot();
expect(fn).toHaveBeenCalledTimes(2);
expect(fn).toHaveBeenCalledTimes(1);
});
});

Expand All @@ -190,26 +187,27 @@ describe('ScrollToLoadMore', () => {

// 模拟点击
// @ts-ignore
scrollToLoadMoreInstance.view.el.click();
// scrollToLoadMoreInstance.view.el.click();
const p = scrollToLoadMoreInstance.triggerLoad();

// loding
expect(document.body.innerHTML).toMatchSnapshot();
expect(fn).toHaveBeenCalledTimes(1);

await fn();
await p;

// failed
expect(document.body.innerHTML).toMatchSnapshot();
expect(fn).toHaveBeenCalledTimes(2);
expect(fn).toHaveBeenCalledTimes(1);

// 模拟点击
// @ts-ignore
scrollToLoadMoreInstance.view.el.click();
await fn();
// scrollToLoadMoreInstance.view.el.click();
await scrollToLoadMoreInstance.triggerLoad();

// success
expect(document.body.innerHTML).toMatchSnapshot();
expect(fn).toHaveBeenCalledTimes(4);
expect(fn).toHaveBeenCalledTimes(2);
});

it('render define', async () => {
Expand All @@ -232,26 +230,27 @@ describe('ScrollToLoadMore', () => {

// 模拟点击
// @ts-ignore
scrollToLoadMoreInstance.view.el.click();
// scrollToLoadMoreInstance.view.el.click();
const p = scrollToLoadMoreInstance.triggerLoad();

// loding
expect(document.body.innerHTML).toMatchSnapshot();
expect(fn).toHaveBeenCalledTimes(1);

await fn();
await p;

// failed
expect(document.body.innerHTML).toMatchSnapshot();
expect(fn).toHaveBeenCalledTimes(2);
expect(fn).toHaveBeenCalledTimes(1);

// 模拟点击
// @ts-ignore
scrollToLoadMoreInstance.view.el.click();
await fn();
// scrollToLoadMoreInstance.view.el.click();
await scrollToLoadMoreInstance.triggerLoad();

// success
expect(document.body.innerHTML).toMatchSnapshot();
expect(fn).toHaveBeenCalledTimes(4);
expect(fn).toHaveBeenCalledTimes(2);
});

it('render update', async () => {
Expand Down Expand Up @@ -280,26 +279,27 @@ describe('ScrollToLoadMore', () => {

// 模拟点击
// @ts-ignore
scrollToLoadMoreInstance.view.el.click();
// scrollToLoadMoreInstance.view.el.click();
const p = scrollToLoadMoreInstance.triggerLoad();

// loding
expect(document.body.innerHTML).toMatchSnapshot();
expect(fn).toHaveBeenCalledTimes(1);

await fn();
await p;

// failed
expect(document.body.innerHTML).toMatchSnapshot();
expect(fn).toHaveBeenCalledTimes(2);
expect(fn).toHaveBeenCalledTimes(1);

// 模拟点击
// @ts-ignore
scrollToLoadMoreInstance.view.el.click();
await fn();
// scrollToLoadMoreInstance.view.el.click();
await scrollToLoadMoreInstance.triggerLoad();

// success
expect(document.body.innerHTML).toMatchSnapshot();
expect(fn).toHaveBeenCalledTimes(4);
expect(fn).toHaveBeenCalledTimes(2);
});

it('destroy & resume', async () => {
Expand All @@ -322,16 +322,16 @@ describe('ScrollToLoadMore', () => {

// resume
scrollToLoadMoreInstance.resume();
scrollToLoadMoreInstance.triggerLoad();
const p = scrollToLoadMoreInstance.triggerLoad();

// loading
expect(document.body.innerHTML).toMatchSnapshot();
expect(fn).toHaveBeenCalledTimes(1);

await fn();
await p;

// default
expect(document.body.innerHTML).toMatchSnapshot();
expect(fn).toHaveBeenCalledTimes(2);
expect(fn).toHaveBeenCalledTimes(1);
});
});
4 changes: 4 additions & 0 deletions tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "./tsconfig.json",
"include": ["src"]
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
/* Language and Environment */
"target": "ES3" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
"target": "ES5" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
"lib": [
"DOM",
"ESNext"
Expand Down

0 comments on commit fc24da9

Please sign in to comment.