Skip to content

Commit

Permalink
chore: Migrate to vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldowseza committed May 30, 2024
1 parent 57b9bf6 commit 9dfb131
Show file tree
Hide file tree
Showing 14 changed files with 5,739 additions and 11,090 deletions.
16,747 changes: 5,689 additions & 11,058 deletions package-lock.json

Large diffs are not rendered by default.

36 changes: 11 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
{
"name": "@cloudscape-design/collection-hooks",
"version": "1.0.0",
"license": "Apache-2.0",
"repository": {
"type": "git",
"url": "https://github.com/cloudscape-design/collection-hooks.git"
},
"homepage": "https://cloudscape.design",
"scripts": {
"lint": "eslint . --ext .ts,.tsx",
"test-08:00": "TZ=America/Los_Angeles jest -o ./src/__tests__/date-utils --coverage=false",
"test+08:00": "TZ=Asia/Brunei jest -o ./src/__tests__/date-utils --coverage=false",
"test-local": "jest",
"test-08:00": "TZ=America/Los_Angeles vitest --run ./src/__tests__/date-utils --coverage=false",
"test+08:00": "TZ=Asia/Brunei vitest --run ./src/__tests__/date-utils --coverage=false",
"test-local": "vitest --run",
"test": "npm run test-08:00 && npm run test+08:00 && npm run test-local",
"clean": "rimraf ./lib",
"prebuild": "npm run clean",
"build": "tsc -p ./tsconfig.json && tsc -p ./tsconfig.cjs.json && node ./scripts/generate-deep-package.js",
"postbuild": "cp package.json README.md LICENSE lib",
"postbuild": "cp package.json README.md LICENSE NOTICE lib",
"prepare": "husky"
},
"type": "module",
Expand All @@ -35,18 +36,20 @@
"cjs",
"mjs",
"package.json",
"README.md"
"README.md",
"LICENSE",
"NOTICE"
],
"peerDependencies": {
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
},
"devDependencies": {
"@testing-library/react": "^11.2.7",
"@types/jest": "^26.0.24",
"@types/react": "^16.14.21",
"@types/react-dom": "^16.9.14",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"@vitest/coverage-istanbul": "^1.6.0",
"eslint": "^7.32.0",
"eslint-config-prettier": "^6.15.0",
"eslint-plugin-header": "3.1.0",
Expand All @@ -55,34 +58,17 @@
"eslint-plugin-react-hooks": "^4.3.0",
"eslint-plugin-unicorn": "^11.0.2",
"husky": "^9.0.0",
"jest": "^26.6.3",
"jest-ts-webcompat-resolver": "^1.0.0",
"lint-staged": "^13.2.1",
"prettier": "^2.5.0",
"react": "^16.14.0",
"react-dom": "^16.14.0",
"rimraf": "^3.0.2",
"ts-jest": "^26.5.6",
"typescript": "^4.5.2"
"typescript": "^4.5.2",
"vitest": "^1.6.0"
},
"lint-staged": {
"*.{js,jsx,ts,tsx}": [
"eslint --fix"
]
},
"jest": {
"preset": "ts-jest",
"resolver": "jest-ts-webcompat-resolver",
"collectCoverage": true,
"collectCoverageFrom": [
"src/**",
"!**/__tests__/**"
],
"globals": {
"ts-jest": {
"tsconfig": "tsconfig.unit.json"
}
},
"testRegex": "/__tests__/.*\\.test\\.tsx?$"
}
}
2 changes: 1 addition & 1 deletion src/__tests__/date-utils/compare-dates.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { test, expect, describe } from 'vitest';
import { compareDates, compareTimestamps } from '../../date-utils/compare-dates';

const localTimezoneOffset = 0 - new Date('2020-01-01').getTimezoneOffset();
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/date-utils/parse-iso-date.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { test, expect } from 'vitest';
import { parseIsoDate } from '../../date-utils/parse-iso-date';

const second = 1 * 1000;
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/operations/combined.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { test, expect } from 'vitest';
import { processItems } from '../../operations';

test('filtering with pagination', () => {
Expand Down
5 changes: 3 additions & 2 deletions src/__tests__/operations/filter.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { test, expect, describe, vi } from 'vitest';
import { processItems } from '../../operations';

test('returns all items when filtering text is empty', () => {
Expand Down Expand Up @@ -110,7 +111,7 @@ describe('with filteringFunction', () => {
});

test('passes filtering text and fields into filtering function', () => {
const filteringSpy = jest.fn(() => true);
const filteringSpy = vi.fn(() => true);
const items = [{ id: 1 }, { id: 2 }, { id: 3 }];
const { items: processed } = processItems(
items,
Expand All @@ -128,7 +129,7 @@ describe('with filteringFunction', () => {
});

test('applies custom filteringFunction even if filtering text is empty', () => {
const filteringSpy = jest.fn(() => true);
const filteringSpy = vi.fn(() => true);
const items = [{ id: 1 }, { id: 2 }, { id: 3 }];
const { items: processed } = processItems(
items,
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/operations/paginate.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { test, expect } from 'vitest';
import { processItems } from '../../operations';

const generateItems = (length: number) => Array.from({ length }, (_, index) => index);
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/operations/process-selected.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { test, expect, describe } from 'vitest';
import { processSelectedItems } from '../../operations';
import { TrackBy } from '../../interfaces';

Expand Down
5 changes: 3 additions & 2 deletions src/__tests__/operations/property-filter.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { test, expect, describe, vi } from 'vitest';
import { processItems } from '../../operations';
import { PropertyFilterOperator } from '../../interfaces';

Expand Down Expand Up @@ -349,7 +350,7 @@ test('unsupported operator results in an exception', () => {
describe('filtering function', () => {
test('Is called with the current query', () => {
const items = [{ id: 1, field: 'match me' }];
const spy = jest.fn();
const spy = vi.fn();
const query = { tokens: [], operation: 'and' } as const;
processItems(
items,
Expand All @@ -365,7 +366,7 @@ describe('filtering function', () => {
});
test('result is used for filtlering', () => {
const items = [{ id: 1, field: 'match me' }];
const spy = jest.fn();
const spy = vi.fn();
spy.mockReturnValue(false);
const query = { tokens: [], operation: 'and' } as const;
const { items: processed } = processItems(
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/operations/sort.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { test, expect } from 'vitest';
import { processItems } from '../../operations';

// ignore the prefix and compare only the numbers
Expand Down
8 changes: 8 additions & 0 deletions src/__tests__/setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { afterEach } from 'vitest';
import { cleanup } from '@testing-library/react';

afterEach(() => {
cleanup();
});
1 change: 1 addition & 0 deletions src/__tests__/use-collection-expadable-rows.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { test, expect } from 'vitest';
import { fireEvent, screen } from '@testing-library/react';
import React from 'react';
import { useCollection } from '..';
Expand Down
3 changes: 2 additions & 1 deletion src/__tests__/use-collection.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { test, expect, describe, vi } from 'vitest';
import { fireEvent, render as testRender } from '@testing-library/react';
import * as React from 'react';
import { useCollection } from '../';
Expand Down Expand Up @@ -170,7 +171,7 @@ test('should prevent pagination from going out of bounds', () => {

test('should evoke scrollToTop from the ref on pagination, filtering, property filtering and sorting', () => {
const allItems = generateItems(50);
const spy = jest.fn();
const spy = vi.fn();
function App() {
const result = useCollection(allItems, {
pagination: {},
Expand Down
16 changes: 16 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { defineConfig } from 'vitest/config';

export default defineConfig({
test: {
environment: 'jsdom',
setupFiles: ['./src/__tests__/setup.ts'],
coverage: {
enabled: process.env.CI === 'true',
provider: 'istanbul',
include: ['src/**'],
exclude: ['**/debug-tools/**', '**/test/**'],
},
},
});

0 comments on commit 9dfb131

Please sign in to comment.