Skip to content
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 the existing tests with deno #179

Closed
wants to merge 12 commits into from
27 changes: 27 additions & 0 deletions .github/workflows/deno.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Deno CI

on:
push:
branches: main
pull_request:

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install Deno
uses: denoland/setup-deno@v1
with:
deno-version: "1.41.1"

- name: Run Deno Test in library
run: deno task test
working-directory: library

- name: Run Deno Check in library
run: deno check mod.ts $(find src -name '*.ts')
working-directory: library
2 changes: 1 addition & 1 deletion library/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
root: true,
ignorePatterns: ['.eslintrc.cjs'],
ignorePatterns: ['.eslintrc.cjs', 'denoVitestPolyfill.ts'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
Expand Down
9 changes: 9 additions & 0 deletions library/deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"lock": false,
"tasks": {
"test": "deno test --allow-read --parallel"
},
"imports": {
"vitest": "./src/testUtils/denoVitestPolyfill.ts"
}
}
8 changes: 8 additions & 0 deletions library/mod.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { describe, expect, test } from 'vitest';

describe('Deno compatibility', () => {
test('should be able to import mod.ts', async () => {
const module = await import('./mod.ts');
expect(module).not.toBeUndefined();
})
});
2 changes: 1 addition & 1 deletion library/src/schemas/lazy/lazy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('lazy', () => {
});

test('should pass the input to the getter function as a parameter', () => {
const getter = vi.fn().mockReturnValue({ _parse: string()._parse });
const getter = vi.fn().mockReturnValue({ _parse: string()._parse }) as any;
const schema = lazy(getter);
const input = 'hello';
parse(schema, input);
Expand Down
4 changes: 3 additions & 1 deletion library/src/schemas/lazy/lazyAsync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ describe('lazyAsync', () => {
});

test('should pass input to getter', async () => {
const getter = vi.fn().mockReturnValue({ _parse: stringAsync()._parse });
const getter = vi
.fn()
.mockReturnValue({ _parse: stringAsync()._parse }) as any;
const schema = lazyAsync(getter);
const input = 'hello';
await parseAsync(schema, input);
Expand Down
2 changes: 1 addition & 1 deletion library/src/schemas/record/record.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ describe('record', () => {
expect(input.__proto__.polluted).toBe('yes');
expect(({} as any).polluted).toBeUndefined();
const output = parse(schema, input);
expect(output.__proto__.polluted).toBeUndefined();
expect(output.__proto__?.polluted).toBeUndefined();
expect(output.polluted).toBeUndefined();
});

Expand Down
2 changes: 1 addition & 1 deletion library/src/schemas/record/recordAsync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ describe('recordAsync', () => {
expect(input.__proto__.polluted).toBe('yes');
expect(({} as any).polluted).toBeUndefined();
const output = await parseAsync(schema, input);
expect(output.__proto__.polluted).toBeUndefined();
expect(output.__proto__?.polluted).toBeUndefined();
expect(output.polluted).toBeUndefined();
});

Expand Down
9 changes: 9 additions & 0 deletions library/src/testUtils/denoVitestPolyfill.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import jestExpect from 'npm:expect@29.7.0';
import jestFn from 'npm:jest-mock@29.7.0';

export * from 'jsr:@std/testing@0.218.2/bdd';
export { it as test } from 'jsr:@std/testing@0.218.2/bdd';
export { expectTypeOf } from 'npm:expect-type@0.16.0';

export const expect = jestExpect.default;
export const vi = { fn: jestFn.fn };
3 changes: 2 additions & 1 deletion library/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
"skipLibCheck": true,
"noEmit": true
},
"include": ["src", "./*.config.ts"]
"include": ["src", "./*.config.ts"],
"exclude": ["src/testUtils/denoVitestPolyfill.ts"]
}
Loading