-
Notifications
You must be signed in to change notification settings - Fork 224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Run a Codeshift to move away from the custom test runner #1274
Changes from all commits
c465643
0b2ce91
897a297
c46e9d3
a5a759f
122c514
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/bash | ||
|
||
# Define the relative directory path | ||
DIR="test/validation" | ||
|
||
# Find all .ts and .tsx files in the specified directory and rename them | ||
find "$DIR" -type f \( -name "*.ts" -o -name "*.tsx" \) | while read -r file; do | ||
# Construct the new file name with .test.ts extension | ||
new_file="${file%.*}.test.ts" | ||
|
||
# Rename the file | ||
mv "$file" "$new_file" | ||
|
||
echo "Renamed $file to $new_file" | ||
done |
This file was deleted.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. File for adding custom matchers, which includes The old test runner would check for a failure, and check that the |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { isEqual, pick } from 'lodash' | ||
import { expect } from 'vitest' | ||
import { StructError } from '../src' | ||
|
||
const FILTERED_PROPS = ['type', 'path', 'refinement', 'value', 'branch'] | ||
|
||
expect.extend({ | ||
toMatchStructError: (received: StructError | undefined, expected: any) => { | ||
// Make sure the error exists | ||
if (!(received instanceof StructError)) { | ||
return { | ||
message: () => `Expected error to be a StructError`, | ||
pass: false, | ||
actual: received, | ||
expected, | ||
} | ||
} | ||
|
||
const actualFailures = received | ||
.failures() | ||
.map((failure) => pick(failure, ...FILTERED_PROPS)) | ||
|
||
// Check that the failures match | ||
if (!isEqual(actualFailures, expected)) { | ||
return { | ||
message: () => `Expected error.failures to match expected`, | ||
pass: false, | ||
actual: actualFailures, | ||
expected, | ||
} | ||
} | ||
|
||
const strippedError = pick(received, ...FILTERED_PROPS) | ||
|
||
// Check that the first failure properties are also the properties of the StructError | ||
if (!isEqual(strippedError, expected[0])) { | ||
return { | ||
message: () => | ||
`Expected error properties to match first expected failure`, | ||
pass: false, | ||
actual: strippedError, | ||
expected, | ||
} | ||
} | ||
|
||
return { | ||
message: () => `${received} matches ${expected}`, | ||
pass: true, | ||
} | ||
}, | ||
}) | ||
|
||
interface CustomMatchers { | ||
toMatchStructError: (expected: any) => void | ||
} | ||
|
||
declare module 'vitest' { | ||
interface Assertion extends CustomMatchers {} | ||
interface AsymmetricMatchersContaining extends CustomMatchers {} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { assert } from '../../../src' | ||
import { expect, test } from 'vitest' | ||
import { any } from '../../../src' | ||
|
||
test('Valid any number', () => { | ||
const data = 1 | ||
assert(data, any()) | ||
expect(data).toStrictEqual(1) | ||
}) |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { assert } from '../../../src' | ||
import { expect, test } from 'vitest' | ||
import { any } from '../../../src' | ||
|
||
test('Valid any string', () => { | ||
const data = 'valid' | ||
assert(data, any()) | ||
expect(data).toStrictEqual('valid') | ||
}) |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { assert } from '../../../src' | ||
import { expect, test } from 'vitest' | ||
import { any } from '../../../src' | ||
|
||
test('Valid any undefined', () => { | ||
const data = undefined | ||
assert(data, any()) | ||
expect(data).toStrictEqual(undefined) | ||
}) |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { validate } from '../../../src' | ||
import { expect, test } from 'vitest' | ||
import { array, object, string } from '../../../src' | ||
|
||
test('Invalid array element property', () => { | ||
const data = [{ id: '1' }, { id: false }, { id: '3' }] | ||
const [err, res] = validate(data, array(object({ id: string() }))) | ||
expect(res).toBeUndefined() | ||
|
||
expect(err).toMatchStructError([ | ||
{ | ||
value: false, | ||
type: 'string', | ||
refinement: undefined, | ||
path: [1, 'id'], | ||
branch: [data, data[1], data[1].id], | ||
}, | ||
]) | ||
}) |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { validate } from '../../../src' | ||
import { expect, test } from 'vitest' | ||
import { array, number } from '../../../src' | ||
|
||
test('Invalid array element', () => { | ||
const data = [1, 'invalid', 3] | ||
const [err, res] = validate(data, array(number())) | ||
expect(res).toBeUndefined() | ||
|
||
expect(err).toMatchStructError([ | ||
{ | ||
value: 'invalid', | ||
type: 'number', | ||
refinement: undefined, | ||
path: [1], | ||
branch: [data, data[1]], | ||
}, | ||
]) | ||
}) |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { validate } from '../../../src' | ||
import { expect, test } from 'vitest' | ||
import { array } from '../../../src' | ||
|
||
test('Invalid array opaque', () => { | ||
const data = 'invalid' | ||
const [err, res] = validate(data, array()) | ||
expect(res).toBeUndefined() | ||
|
||
expect(err).toMatchStructError([ | ||
{ | ||
value: 'invalid', | ||
type: 'array', | ||
refinement: undefined, | ||
path: [], | ||
branch: [data], | ||
}, | ||
]) | ||
}) |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { validate } from '../../../src' | ||
import { expect, test } from 'vitest' | ||
import { array, number } from '../../../src' | ||
|
||
test('Invalid array', () => { | ||
const data = 'invalid' | ||
const [err, res] = validate(data, array(number())) | ||
expect(res).toBeUndefined() | ||
|
||
expect(err).toMatchStructError([ | ||
{ | ||
value: 'invalid', | ||
type: 'array', | ||
refinement: undefined, | ||
path: [], | ||
branch: [data], | ||
}, | ||
]) | ||
}) |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { create } from '../../../src' | ||
import { expect, test } from 'vitest' | ||
import { array, number } from '../../../src' | ||
|
||
test('Valid array frozen', () => { | ||
const data = Object.freeze([1, 2, 3]) | ||
const res = create(data, array(number())) | ||
expect(res).toStrictEqual([1, 2, 3]) | ||
}) |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { assert } from '../../../src' | ||
import { expect, test } from 'vitest' | ||
import { array } from '../../../src' | ||
|
||
test('Valid array opaque', () => { | ||
const data = [1, 'b', true] | ||
assert(data, array()) | ||
expect(data).toStrictEqual([1, 'b', true]) | ||
}) |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is the script for renaming the files to end with
.test.ts