Skip to content

Commit

Permalink
feat: vitest and bump (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
Innei authored Mar 13, 2023
1 parent 590358f commit 2afdef7
Show file tree
Hide file tree
Showing 13 changed files with 2,209 additions and 2,084 deletions.
35 changes: 35 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module.exports = {
extends: ['@innei/eslint-config-ts'],
root: true,
plugins: ['unused-imports', '@typescript-eslint'],
rules: {
'no-empty': 'warn',
'no-fallthrough': 'error',
'no-unused-vars': 'off', // or "@typescript-eslint/no-unused-vars": "off",
'@typescript-eslint/no-unused-vars': 'off',
'unused-imports/no-unused-imports': 'error',
'@typescript-eslint/consistent-type-imports': [
'warn',
{
prefer: 'no-type-imports',
},
],
'unused-imports/no-unused-vars': [
'warn',
{
vars: 'all',
varsIgnorePattern: '^_',
args: 'after-used',
argsIgnorePattern: '^_',
},
],
},
overrides: [
{
files: ['src/migration/**/*.ts'],
rules: {
'import/no-default-export': 'off',
},
},
],
}
4 changes: 4 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# https://zenn.dev/haxibami/scraps/083718c1beec04
strict-peer-dependencies=false

registry=https://registry.npmjs.org
1 change: 1 addition & 0 deletions .prettierrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('@innei/prettier')
22 changes: 0 additions & 22 deletions jest.config.js

This file was deleted.

25 changes: 14 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"scripts": {
"clean": "pnpm run -r clean",
"build": "pnpm run -r build",
"test": "pnpm run -r test",
"test": "CI=true pnpm run -r test",
"version": "bump",
"alpha": "bump --branch",
"lint": "eslint --ext js,ts,tsx .",
Expand All @@ -26,7 +26,7 @@
"enable": true,
"skipUnstable": true
},
"publish": false,
"publish": true,
"allowed_branches": [
{
"name": ".*?-alpha",
Expand All @@ -53,6 +53,11 @@
"mode": "monorepo",
"packages": [
"packages/*"
],
"before": [
"git pull --rebase",
"pnpm i",
"npm run build"
]
},
"lint-staged": {
Expand All @@ -70,19 +75,17 @@
"author": "youchao liu",
"license": "ISC",
"devDependencies": {
"@innei/bump-version": "1.4.0",
"@testing-library/jest-dom": "^5.11.10",
"@types/jest": "^27.5.2",
"@innei/bump-version": "1.5.9",
"@innei/eslint-config-ts": "0.9.7",
"@innei/prettier": "0.9.7",
"@types/node": "^16",
"husky": "^8.0.1",
"jest": "^29.5.0",
"jest-transform-stub": "^2.0.0",
"lint-staged": "^13.0.3",
"rimraf": "^3.0.2",
"ts-jest": "^29.0.5",
"ts-node": "^10.5.0",
"tslib": "^2.3.1",
"typescript": "4.8.3"
"typescript": "4.8.3",
"vite": "4.1.4",
"vite-tsconfig-paths": "4.0.5",
"vitest": "0.29.2"
},
"bugs": {
"url": "https://github.com/red-armor/infinite-list/issues"
Expand Down
27 changes: 0 additions & 27 deletions packages/data-model/jest.config.js

This file was deleted.

4 changes: 2 additions & 2 deletions packages/data-model/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"scripts": {
"build": "pnpm run clean && pnpm run compile",
"clean": "rimraf ./dist",
"test": "jest --verbose",
"compile": "tsc -p tsconfig.build.json",
"prepublishOnly": "pnpm run build"
"prepublishOnly": "pnpm run build",
"test": "vitest"
},
"devDependencies": {
"rimraf": "~4.4.0"
Expand Down
84 changes: 43 additions & 41 deletions packages/data-model/src/__test__/ListDimensions.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import ListDimensions from '../ListDimensions';
import Batchinator from '../batcher/Batchinator';
import { defaultKeyExtractor } from '../exportedUtils';
import { KeysChangedType } from '../types';
import ListDimensions from '../ListDimensions'
import Batchinator from '../batcher/Batchinator'
import { defaultKeyExtractor } from '../exportedUtils'
import { KeysChangedType } from '../types'
import { vi, describe, it, expect } from 'vitest'
const buildData = (count: number) =>
new Array(count).fill(1).map((v, index) => ({
key: index,
}));
}))

jest
.spyOn(Batchinator.prototype, 'schedule')
.mockImplementation(function(...args) {
this._callback.apply(this, args);
});
vi.spyOn(Batchinator.prototype, 'schedule').mockImplementation(function (
...args
) {
// eslint-disable-next-line prefer-spread
this._callback.apply(this, args)
})

describe('basic', () => {
it('constructor', () => {
Expand All @@ -30,35 +32,35 @@ describe('basic', () => {
width: 375,
height: 2000,
}),
});
})

expect(listDimensions.maxToRenderPerBatch).toBe(7);
expect(listDimensions.windowSize).toBe(9);
expect(listDimensions.initialNumToRender).toBe(20);
expect(listDimensions.onEndReachedThreshold).toBe(300);
expect(listDimensions.horizontal).toBe(true);
});
expect(listDimensions.maxToRenderPerBatch).toBe(7)
expect(listDimensions.windowSize).toBe(9)
expect(listDimensions.initialNumToRender).toBe(20)
expect(listDimensions.onEndReachedThreshold).toBe(300)
expect(listDimensions.horizontal).toBe(true)
})

it('verify changedType', () => {
const data = buildData(10);
const data = buildData(10)

const listDimensions = new ListDimensions({
id: 'list_1',
data,
keyExtractor: defaultKeyExtractor,
});
})

const nextData = data.slice();
nextData.splice(3, 1);
const changedType = listDimensions.setData(nextData);
expect(changedType).toBe(KeysChangedType.Remove);
const nextData = data.slice()
nextData.splice(3, 1)
const changedType = listDimensions.setData(nextData)
expect(changedType).toBe(KeysChangedType.Remove)

const changedTypeAdd = listDimensions.setData(buildData(12));
expect(changedTypeAdd).toBe(KeysChangedType.Add);
});
const changedTypeAdd = listDimensions.setData(buildData(12))
expect(changedTypeAdd).toBe(KeysChangedType.Add)
})

it('initial itemMeta instance layout -- with getItemLayout', () => {
const data = buildData(10);
const data = buildData(10)

const listDimensions = new ListDimensions({
id: 'list_1',
Expand All @@ -68,34 +70,34 @@ describe('basic', () => {
index,
length: 100,
}),
});
})

data.forEach((item, index) => {
const meta = listDimensions.getItemMeta(item, index);
const meta = listDimensions.getItemMeta(item, index)
expect(meta.getLayout()).toEqual({
x: 0,
y: 0,
height: 100,
width: 0,
});
});
})
})

expect(listDimensions.getReflowItemsLength()).toBe(10);
});
expect(listDimensions.getReflowItemsLength()).toBe(10)
})

it('initial itemMeta instance layout -- without getItemLayout', () => {
const data = buildData(10);
const data = buildData(10)

const listDimensions = new ListDimensions({
id: 'list_1',
data,
keyExtractor: defaultKeyExtractor,
});
})

data.forEach((item, index) => {
const meta = listDimensions.getItemMeta(item, index);
expect(meta.getLayout()).toBeUndefined();
});
expect(listDimensions.getReflowItemsLength()).toBe(0);
});
});
const meta = listDimensions.getItemMeta(item, index)
expect(meta.getLayout()).toBeUndefined()
})
expect(listDimensions.getReflowItemsLength()).toBe(0)
})
})
Loading

0 comments on commit 2afdef7

Please sign in to comment.