Skip to content

Commit

Permalink
fix[tests]: use vitest .each convention for tests
Browse files Browse the repository at this point in the history
additionally clean up folder names for fixtures.

issue #11
  • Loading branch information
kalisjoshua committed Nov 20, 2024
1 parent 86604c4 commit a4aa174
Show file tree
Hide file tree
Showing 31 changed files with 6,879 additions and 6,961 deletions.
13,260 changes: 6,630 additions & 6,630 deletions .secrets.baseline

Large diffs are not rendered by default.

45 changes: 45 additions & 0 deletions packages/__fixtures__/boolean.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2024 Hypergiant Galactic Systems Inc. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/

// biome-ignore lint/suspicious/noExplicitAny: <explanation>
type Callable = (...a: any[]) => any;
type Fixture = [string, boolean, Callable, Values][];
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
type Values = any[];

export const truthy: Values = [
1,
'1',
'on',
'true',
'yes',
true,
'ON',
'YES',
'TRUE',
];
export const falsey: Values = [
0,
'0',
'off',
'false',
'no',
false,
[],
{},
'OFF',
'NO',
'FALSE',
];

export const createFixture = (bool: boolean, ...rest: [Values, Callable][]) =>
rest.map(([values, fn]) => [fn.name, bool, fn, values]) as Fixture;
4 changes: 1 addition & 3 deletions packages/constants/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
"private": false,
"license": "Apache-2.0",
"type": "module",
"files": [
"dist/**"
],
"files": ["dist/**"],
"types": "./dist/index.d.ts",
"exports": {
".": {
Expand Down
2 changes: 1 addition & 1 deletion packages/constants/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default defineConfig({
entry: [
'src/**/*.{ts,tsx}',
'!src/**/*.{d,stories,test,test-d,bench}.{ts,tsx}',
'!**/__fixture__',
'!**/__fixtures__',
],
bundle: true,
clean: true,
Expand Down
4 changes: 1 addition & 3 deletions packages/converters/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
"private": false,
"license": "Apache-2.0",
"type": "module",
"files": [
"dist/**"
],
"files": ["dist/**"],
"types": "./dist/index.d.ts",
"exports": {
".": {
Expand Down
17 changes: 7 additions & 10 deletions packages/converters/src/boolean-to-number/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,12 @@
import { describe, expect, it } from 'vitest';
import { booleanToNumber } from './';

const testPairs: [boolean, number][] = [
[true, 1],
[false, 0],
];

describe('bool to number', () => {
for (const [input, result] of testPairs) {
it(`should convert ${input} to ${result}`, () => {
expect(booleanToNumber(input)).toEqual(result);
});
}
it.each`
input | result
${true} | ${1}
${false} | ${0}
`('should convert $input to $result', ({ input, result }) => {
expect(booleanToNumber(input)).toEqual(result);
});
});
39 changes: 13 additions & 26 deletions packages/converters/src/to-boolean/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,21 @@
* governing permissions and limitations under the License.
*/

import { expect, it, describe } from 'vitest';
import { toBoolean } from './';
import { describe, expect, it } from 'vitest';

const truthy = [1, '1', 'on', 'true', 'yes', true, 'ON', 'YES', 'TRUE'];
const falsey = [
0,
'0',
'off',
'false',
'no',
false,
[],
{},
'OFF',
'NO',
'FALSE',
];
import { createFixture, falsey, truthy } from '../../../__fixtures__/boolean';

describe('toBoolean', () => {
for (const item of truthy) {
it(`should return true for ${item}`, () => {
expect(toBoolean(item)).toBeTruthy();
});
}
import { toBoolean } from './';

for (const item of falsey) {
it(`should return false for ${item}`, () => {
expect(toBoolean(item)).not.toBeTruthy();
describe('toBoolean', () => {
describe.each([
// positive cases
...createFixture(true, [truthy, toBoolean]),
// negative cases
...createFixture(false, [falsey, toBoolean]),
])('%s', (_name, expected, fn, values) => {
it.each(values)(`should return "${expected}" for %j`, (value) => {
expect(fn(value)).toBe(expected);
});
}
});
});
2 changes: 1 addition & 1 deletion packages/converters/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default defineConfig({
entry: [
'src/**/*.{ts,tsx}',
'!src/**/*.{d,stories,test,test-d,bench}.{ts,tsx}',
'!**/__fixture__',
'!**/__fixtures__',
],
bundle: true,
clean: true,
Expand Down
4 changes: 1 addition & 3 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
"private": false,
"license": "Apache-2.0",
"type": "module",
"files": [
"dist/**"
],
"files": ["dist/**"],
"types": "./dist/index.d.ts",
"exports": {
".": {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default defineConfig({
entry: [
'src/**/*.{ts,tsx}',
'!src/**/*.{d,stories,test,test-d,bench}.{ts,tsx}',
'!**/__fixture__',
'!**/__fixtures__',
],
bundle: true,
clean: true,
Expand Down
4 changes: 1 addition & 3 deletions packages/design-system/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
"private": false,
"sideEffects": false,
"type": "module",
"files": [
"dist/**"
],
"files": ["dist/**"],
"types": "./dist/index.d.ts",
"exports": {
".": {
Expand Down
4 changes: 1 addition & 3 deletions packages/formatters/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
"private": false,
"license": "Apache-2.0",
"type": "module",
"files": [
"dist/**"
],
"files": ["dist/**"],
"types": "./dist/index.d.ts",
"exports": {
".": {
Expand Down
2 changes: 1 addition & 1 deletion packages/formatters/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default defineConfig({
entry: [
'src/**/*.{ts,tsx}',
'!src/**/*.{d,stories,test,test-d,bench}.{ts,tsx}',
'!**/__fixture__',
'!**/__fixtures__',
],
bundle: true,
clean: true,
Expand Down
4 changes: 1 addition & 3 deletions packages/geo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
"private": false,
"license": "Apache-2.0",
"type": "module",
"files": [
"dist/**"
],
"files": ["dist/**"],
"types": "./dist/index.d.ts",
"exports": {
".": {
Expand Down
2 changes: 1 addition & 1 deletion packages/geo/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default defineConfig({
entry: [
'src/**/*.{ts,tsx}',
'!src/**/*.{d,stories,test,test-d,bench}.{ts,tsx}',
'!**/__fixture__',
'!**/__fixtures__',
],
bundle: true,
clean: true,
Expand Down
4 changes: 1 addition & 3 deletions packages/math/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
"private": false,
"license": "Apache-2.0",
"type": "module",
"files": [
"dist/**"
],
"files": ["dist/**"],
"types": "./dist/index.d.ts",
"exports": {
".": {
Expand Down
2 changes: 1 addition & 1 deletion packages/math/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default defineConfig({
entry: [
'src/**/*.{ts,tsx}',
'!src/**/*.{d,stories,test,test-d,bench}.{ts,tsx}',
'!**/__fixture__',
'!**/__fixtures__',
],
bundle: true,
clean: true,
Expand Down
4 changes: 1 addition & 3 deletions packages/predicates/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
"private": false,
"license": "Apache-2.0",
"type": "module",
"files": [
"dist/**"
],
"files": ["dist/**"],
"types": "./dist/index.d.ts",
"exports": {
".": {
Expand Down
41 changes: 25 additions & 16 deletions packages/predicates/src/is-noyes/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,33 @@
* governing permissions and limitations under the License.
*/

import { describe, it, expect } from 'vitest';
import { isTrue, isYes, isFalse, isNo } from './';
import { describe, expect, it } from 'vitest';

const truthy = [1, '1', 'on', 'true', 'yes', true, 'ON', 'YES', 'TRUE'];
const falsey = [0, '0', 'off', 'false', 'no', false, 'OFF', 'NO', 'FALSE'];
import { createFixture, falsey, truthy } from '../../../__fixtures__/boolean';

describe('boolean validators', () => {
for (const item of truthy) {
it(`should return true for ${item}`, () => {
expect(isTrue(item)).toBeTruthy();
expect(isYes(item)).toBeTruthy();
});
}
import { isFalse, isNo, isTrue, isYes } from './';

for (const item of falsey) {
it(`should return false for ${item}`, () => {
expect(isFalse(item)).toBeTruthy();
expect(isNo(item)).toBeTruthy();
describe('boolean validators', () => {
describe.each([
// positive cases
...createFixture(
true,
[falsey, isFalse],
[falsey, isNo],
[truthy, isTrue],
[truthy, isYes],
),
// negative cases
...createFixture(
false,
[truthy, isFalse],
[truthy, isNo],
[falsey, isTrue],
[falsey, isYes],
),
])('%s', (_name, expected, fn, values) => {
it.each(values)(`should return "${expected}" for %j`, (value) => {
expect(fn(value)).toBe(expected);
});
}
});
});
Loading

0 comments on commit a4aa174

Please sign in to comment.