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

test: migrate to vitest #1536

Merged
merged 34 commits into from Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
5df6433
test: migrate to vitest
saihaj Dec 7, 2023
2096976
migrate add tests
saihaj Dec 11, 2023
566126f
use vitest
saihaj Dec 11, 2023
31ec98d
prettier
saihaj Dec 11, 2023
7482af0
remove jest
saihaj Dec 11, 2023
ed240e2
fix ci
saihaj Dec 11, 2023
e37aa4e
overwrite timeout
saihaj Dec 11, 2023
c393e11
prettier
saihaj Dec 11, 2023
9e26797
increase timeout for validation tests
saihaj Dec 11, 2023
66c49e9
use snapshots
saihaj Dec 15, 2023
92e27fd
keep
saihaj Dec 15, 2023
b3cf394
move
saihaj Dec 15, 2023
6253b14
trigger
saihaj Dec 15, 2023
66cdef5
upgrade prettier
saihaj Dec 15, 2023
37f5beb
fix codegen issue
saihaj Dec 15, 2023
c71762d
chore(dependencies): updated changesets for modified dependencies
github-actions[bot] Dec 15, 2023
bb3233f
trigger
saihaj Dec 15, 2023
184ac1b
fix
saihaj Dec 15, 2023
1761e64
test cli for v21 only
enisdenjo Dec 18, 2023
6bf545a
no guild shared config
enisdenjo Dec 18, 2023
5dd7b05
pnpm install no frozen lockfile
enisdenjo Dec 18, 2023
4f82bb5
cli test all node versions
enisdenjo Dec 18, 2023
33fcc18
setup node with version from matrix
enisdenjo Dec 18, 2023
42d9813
no no frozen lockfile
enisdenjo Dec 18, 2023
a080462
dont use pnpm cache in ci
enisdenjo Dec 18, 2023
ee88ea0
no parallel matrix
enisdenjo Dec 18, 2023
97c24aa
max parallel 1
enisdenjo Dec 18, 2023
38075de
revert ci changes
enisdenjo Dec 18, 2023
5a3d420
run init test sequentially
enisdenjo Dec 18, 2023
ad7a609
supress node warnings during tests
enisdenjo Dec 18, 2023
9c2dd05
comment
enisdenjo Dec 18, 2023
6e88715
node no warnings as env on job
enisdenjo Dec 18, 2023
cd6c9c8
node no warnings directly in test script
enisdenjo Dec 18, 2023
e860507
NODE_NO_WARNINGS in vitest config
enisdenjo Dec 18, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/@graphprotocol_graph-cli-1536-dependencies.md
@@ -0,0 +1,5 @@
---
"@graphprotocol/graph-cli": patch
---
dependencies updates:
- Updated dependency [`prettier@3.0.3` ↗︎](https://www.npmjs.com/package/prettier/v/3.0.3) (from `1.19.1`, in `dependencies`)
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Expand Up @@ -40,7 +40,7 @@ jobs:
- uses: the-guild-org/shared-config/setup@main
name: Setup Env
with:
nodeVersion: 20
nodeVersion: ${{ matrix.node-version }}
packageManager: pnpm
packageManagerVersion: 8.10.4

Expand All @@ -57,7 +57,7 @@ jobs:
with:
timeout_minutes: 10
max_attempts: 3
command: pnpm run test:cli -- --forceExit
command: pnpm run test:cli

event-handler:
name: Ethereum Basic Event Handlers
Expand Down Expand Up @@ -110,4 +110,4 @@ jobs:
with:
timeout_minutes: 10
max_attempts: 3
command: pnpm run test:ts -- --forceExit
command: pnpm run test:ts
2 changes: 0 additions & 2 deletions package.json
Expand Up @@ -33,9 +33,7 @@
"@theguild/eslint-config": "0.11.0",
"@theguild/prettier-config": "2.0.1",
"@types/node": "^20.6.2",
"babel-jest": "^29.3.1",
"eslint": "8.52.0",
"jest": "29.7.0",
"prettier": "3.0.3"
},
"pnpm": {
Expand Down
175 changes: 0 additions & 175 deletions packages/cli/jest.config.js

This file was deleted.

15 changes: 7 additions & 8 deletions packages/cli/package.json
Expand Up @@ -21,10 +21,10 @@
"scripts": {
"build": "tsc -b tsconfig.build.json && oclif manifest && oclif readme && copyfiles -u 1 src/**/*.graphql dist/",
"oclif:pack": "npm pack && pnpm oclif pack tarballs --no-xz && node scripts/rename-tarballs.mjs",
"test": "jest --verbose",
"test:add": "jest tests/cli/add.test.ts --verbose",
"test:init": "jest tests/cli/init.test.ts --verbose",
"test:validation": "jest tests/cli/validation.test.ts --verbose",
"test": "vitest run --bail=1",
"test:add": "vitest run tests/cli/add.test.ts",
"test:init": "vitest run tests/cli/init.test.ts",
"test:validation": "vitest run tests/cli/validation.test.ts",
"type-check": "tsc --noEmit"
},
"dependencies": {
Expand All @@ -48,7 +48,7 @@
"ipfs-http-client": "55.0.0",
"jayson": "4.0.0",
"js-yaml": "3.14.1",
"prettier": "1.19.1",
"prettier": "3.0.3",
"request": "2.88.2",
"semver": "7.4.0",
"sync-request": "6.1.0",
Expand All @@ -60,17 +60,16 @@
"devDependencies": {
"@types/debug": "^4.1.7",
"@types/fs-extra": "^9.0.13",
"@types/jest": "^29.0.0",
"@types/js-yaml": "^3.12.7",
"@types/semver": "^7.3.13",
"@types/which": "^2.0.1",
"copyfiles": "^2.4.1",
"jest": "29.7.0",
"oclif": "3.8.1",
"spawn-command": "0.0.2-1",
"strip-ansi": "6.0.1",
"tern": "0.24.3",
"typescript": "^5.0.0"
"typescript": "^5.0.0",
"vitest": "^1.0.2"
},
"publishConfig": {
"access": "public"
Expand Down
26 changes: 14 additions & 12 deletions packages/cli/src/codegen/schema.test.ts
@@ -1,16 +1,18 @@
import assert from 'assert';
import * as graphql from 'graphql/language';
import prettier from 'prettier';
import { describe, expect, test } from 'vitest';
import Schema from '../schema';
import SchemaCodeGenerator from './schema';
import { Class, Method, NamedType, NullableType, Param, StaticMethod } from './typescript';

const formatTS = (code: string) => prettier.format(code, { parser: 'typescript', semi: false });
const formatTS = async (code: string) =>
await prettier.format(code, { parser: 'typescript', semi: false });

const createSchemaCodeGen = (schema: string) =>
new SchemaCodeGenerator(new Schema('', schema, graphql.parse(schema)));

const testEntity = (generatedTypes: any[], expectedEntity: any) => {
const testEntity = async (generatedTypes: any[], expectedEntity: any) => {
const entity = generatedTypes.find(type => type.name === expectedEntity.name);

expect(entity instanceof Class).toBe(true);
Expand All @@ -30,13 +32,13 @@ const testEntity = (generatedTypes: any[], expectedEntity: any) => {
: expect(method instanceof Method).toBe(true);
expect(method.params).toStrictEqual(expectedMethod.params);
expect(method.returnType).toStrictEqual(expectedMethod.returnType);
expect(formatTS(method.body)).toBe(formatTS(expectedMethod.body));
expect(await formatTS(method.body)).toBe(await formatTS(expectedMethod.body));
}

expect(methods.length).toBe(expectedEntity.methods.length);
};

describe('Schema code generator', () => {
describe.concurrent('Schema code generator', () => {
test('Should generate nothing for non entity types', () => {
const codegen = createSchemaCodeGen(`
type Foo {
Expand Down Expand Up @@ -93,8 +95,8 @@ describe('Schema code generator', () => {
expect(generatedTypes.length).toBe(2);
});

test('Account is an entity with the correct methods', () => {
testEntity(generatedTypes, {
test('Account is an entity with the correct methods', async () => {
await testEntity(generatedTypes, {
name: 'Account',
members: [],
methods: [
Expand Down Expand Up @@ -297,8 +299,8 @@ describe('Schema code generator', () => {
});
});

test('Wallet is an entity with the correct methods', () => {
testEntity(generatedTypes, {
test('Wallet is an entity with the correct methods', async () => {
await testEntity(generatedTypes, {
name: 'Wallet',
members: [],
methods: [
Expand Down Expand Up @@ -409,7 +411,7 @@ describe('Schema code generator', () => {
});
});

test('Should handle references with Bytes id types', () => {
test('Should handle references with Bytes id types', async () => {
const codegen = createSchemaCodeGen(`
interface Employee {
id: Bytes!
Expand All @@ -431,7 +433,7 @@ describe('Schema code generator', () => {
`);

const generatedTypes = codegen.generateTypes();
testEntity(generatedTypes, {
await testEntity(generatedTypes, {
name: 'Task',
members: [],
methods: [
Expand Down Expand Up @@ -537,7 +539,7 @@ describe('Schema code generator', () => {
});
});

test('get related method for WithBytes entity', () => {
test('get related method for WithBytes entity', async () => {
const codegen = createSchemaCodeGen(`
type WithBytes @entity {
id: Bytes!
Expand All @@ -552,7 +554,7 @@ describe('Schema code generator', () => {

const generatedTypes = codegen.generateTypes();

testEntity(generatedTypes, {
await testEntity(generatedTypes, {
name: 'WithBytes',
members: [],
methods: [
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/codegen/types/index.test.ts
@@ -1,6 +1,7 @@
import { describe, expect, test } from 'vitest';
import * as codegen from '.';

describe('ethereum.Value -> AssemblyScript', () => {
describe.concurrent('ethereum.Value -> AssemblyScript', () => {
// Scalar values

test('address -> Address', () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/codegen/util.test.ts
@@ -1,6 +1,7 @@
import { describe, expect, test } from 'vitest';
import { disambiguateNames, unrollTuple } from './util';

describe('Codegen utilities', () => {
describe.concurrent('Codegen utilities', () => {
test('Name disambiguation', () => {
expect(
disambiguateNames({
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/command-helpers/abi.test.ts
@@ -1,3 +1,4 @@
import { describe, expect, test } from 'vitest';
import { getStartBlockForContract } from './abi';

// An object with some test cases for contract deployment block numbers
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/command-helpers/compiler.test.ts
@@ -1,6 +1,7 @@
import { describe, expect, it } from 'vitest';
import { appendApiVersionForGraph } from './compiler';

describe('appendApiVersionForGraph', () => {
describe.concurrent('appendApiVersionForGraph', () => {
it('append /api/v0 to Prod URL with trailing slash', () => {
expect(appendApiVersionForGraph('https://api.thegraph.com/ipfs/')).toBe(
'https://api.thegraph.com/ipfs/api/v0',
Expand Down