Skip to content

Commit fbce626

Browse files
saihajgithub-actions[bot]enisdenjo
authored
test: migrate to vitest (#1536)
* test: migrate to vitest * migrate add tests * use vitest * prettier * remove jest * fix ci * overwrite timeout * prettier * increase timeout for validation tests * use snapshots * keep * move * trigger * upgrade prettier * fix codegen issue * chore(dependencies): updated changesets for modified dependencies * trigger * fix * test cli for v21 only * no guild shared config * pnpm install no frozen lockfile * cli test all node versions * setup node with version from matrix * no no frozen lockfile * dont use pnpm cache in ci * no parallel matrix * max parallel 1 * revert ci changes * run init test sequentially * supress node warnings during tests * comment * node no warnings as env on job * node no warnings directly in test script * NODE_NO_WARNINGS in vitest config --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: enisdenjo <[email protected]>
1 parent 54cb096 commit fbce626

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+2957
-2478
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@graphprotocol/graph-cli": patch
3+
---
4+
dependencies updates:
5+
- Updated dependency [`[email protected]` ↗︎](https://www.npmjs.com/package/prettier/v/3.0.3) (from `1.19.1`, in `dependencies`)

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
- uses: the-guild-org/shared-config/setup@main
4141
name: Setup Env
4242
with:
43-
nodeVersion: 20
43+
nodeVersion: ${{ matrix.node-version }}
4444
packageManager: pnpm
4545
packageManagerVersion: 8.10.4
4646

@@ -57,7 +57,7 @@ jobs:
5757
with:
5858
timeout_minutes: 10
5959
max_attempts: 3
60-
command: pnpm run test:cli -- --forceExit
60+
command: pnpm run test:cli
6161

6262
event-handler:
6363
name: Ethereum Basic Event Handlers
@@ -110,4 +110,4 @@ jobs:
110110
with:
111111
timeout_minutes: 10
112112
max_attempts: 3
113-
command: pnpm run test:ts -- --forceExit
113+
command: pnpm run test:ts

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@
3333
"@theguild/eslint-config": "0.11.0",
3434
"@theguild/prettier-config": "2.0.1",
3535
"@types/node": "^20.6.2",
36-
"babel-jest": "^29.3.1",
3736
"eslint": "8.52.0",
38-
"jest": "29.7.0",
3937
"prettier": "3.0.3"
4038
},
4139
"pnpm": {

packages/cli/jest.config.js

Lines changed: 0 additions & 175 deletions
This file was deleted.

packages/cli/package.json

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
"scripts": {
2222
"build": "tsc -b tsconfig.build.json && oclif manifest && oclif readme && copyfiles -u 1 src/**/*.graphql dist/",
2323
"oclif:pack": "npm pack && pnpm oclif pack tarballs --no-xz && node scripts/rename-tarballs.mjs",
24-
"test": "jest --verbose",
25-
"test:add": "jest tests/cli/add.test.ts --verbose",
26-
"test:init": "jest tests/cli/init.test.ts --verbose",
27-
"test:validation": "jest tests/cli/validation.test.ts --verbose",
24+
"test": "vitest run --bail=1",
25+
"test:add": "vitest run tests/cli/add.test.ts",
26+
"test:init": "vitest run tests/cli/init.test.ts",
27+
"test:validation": "vitest run tests/cli/validation.test.ts",
2828
"type-check": "tsc --noEmit"
2929
},
3030
"dependencies": {
@@ -48,7 +48,7 @@
4848
"ipfs-http-client": "55.0.0",
4949
"jayson": "4.0.0",
5050
"js-yaml": "3.14.1",
51-
"prettier": "1.19.1",
51+
"prettier": "3.0.3",
5252
"request": "2.88.2",
5353
"semver": "7.4.0",
5454
"sync-request": "6.1.0",
@@ -60,17 +60,16 @@
6060
"devDependencies": {
6161
"@types/debug": "^4.1.7",
6262
"@types/fs-extra": "^9.0.13",
63-
"@types/jest": "^29.0.0",
6463
"@types/js-yaml": "^3.12.7",
6564
"@types/semver": "^7.3.13",
6665
"@types/which": "^2.0.1",
6766
"copyfiles": "^2.4.1",
68-
"jest": "29.7.0",
6967
"oclif": "3.8.1",
7068
"spawn-command": "0.0.2-1",
7169
"strip-ansi": "6.0.1",
7270
"tern": "0.24.3",
73-
"typescript": "^5.0.0"
71+
"typescript": "^5.0.0",
72+
"vitest": "^1.0.2"
7473
},
7574
"publishConfig": {
7675
"access": "public"

packages/cli/src/codegen/schema.test.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
import assert from 'assert';
22
import * as graphql from 'graphql/language';
33
import prettier from 'prettier';
4+
import { describe, expect, test } from 'vitest';
45
import Schema from '../schema';
56
import SchemaCodeGenerator from './schema';
67
import { Class, Method, NamedType, NullableType, Param, StaticMethod } from './typescript';
78

8-
const formatTS = (code: string) => prettier.format(code, { parser: 'typescript', semi: false });
9+
const formatTS = async (code: string) =>
10+
await prettier.format(code, { parser: 'typescript', semi: false });
911

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

13-
const testEntity = (generatedTypes: any[], expectedEntity: any) => {
15+
const testEntity = async (generatedTypes: any[], expectedEntity: any) => {
1416
const entity = generatedTypes.find(type => type.name === expectedEntity.name);
1517

1618
expect(entity instanceof Class).toBe(true);
@@ -30,13 +32,13 @@ const testEntity = (generatedTypes: any[], expectedEntity: any) => {
3032
: expect(method instanceof Method).toBe(true);
3133
expect(method.params).toStrictEqual(expectedMethod.params);
3234
expect(method.returnType).toStrictEqual(expectedMethod.returnType);
33-
expect(formatTS(method.body)).toBe(formatTS(expectedMethod.body));
35+
expect(await formatTS(method.body)).toBe(await formatTS(expectedMethod.body));
3436
}
3537

3638
expect(methods.length).toBe(expectedEntity.methods.length);
3739
};
3840

39-
describe('Schema code generator', () => {
41+
describe.concurrent('Schema code generator', () => {
4042
test('Should generate nothing for non entity types', () => {
4143
const codegen = createSchemaCodeGen(`
4244
type Foo {
@@ -93,8 +95,8 @@ describe('Schema code generator', () => {
9395
expect(generatedTypes.length).toBe(2);
9496
});
9597

96-
test('Account is an entity with the correct methods', () => {
97-
testEntity(generatedTypes, {
98+
test('Account is an entity with the correct methods', async () => {
99+
await testEntity(generatedTypes, {
98100
name: 'Account',
99101
members: [],
100102
methods: [
@@ -297,8 +299,8 @@ describe('Schema code generator', () => {
297299
});
298300
});
299301

300-
test('Wallet is an entity with the correct methods', () => {
301-
testEntity(generatedTypes, {
302+
test('Wallet is an entity with the correct methods', async () => {
303+
await testEntity(generatedTypes, {
302304
name: 'Wallet',
303305
members: [],
304306
methods: [
@@ -409,7 +411,7 @@ describe('Schema code generator', () => {
409411
});
410412
});
411413

412-
test('Should handle references with Bytes id types', () => {
414+
test('Should handle references with Bytes id types', async () => {
413415
const codegen = createSchemaCodeGen(`
414416
interface Employee {
415417
id: Bytes!
@@ -431,7 +433,7 @@ describe('Schema code generator', () => {
431433
`);
432434

433435
const generatedTypes = codegen.generateTypes();
434-
testEntity(generatedTypes, {
436+
await testEntity(generatedTypes, {
435437
name: 'Task',
436438
members: [],
437439
methods: [
@@ -537,7 +539,7 @@ describe('Schema code generator', () => {
537539
});
538540
});
539541

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

553555
const generatedTypes = codegen.generateTypes();
554556

555-
testEntity(generatedTypes, {
557+
await testEntity(generatedTypes, {
556558
name: 'WithBytes',
557559
members: [],
558560
methods: [

packages/cli/src/codegen/types/index.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import { describe, expect, test } from 'vitest';
12
import * as codegen from '.';
23

3-
describe('ethereum.Value -> AssemblyScript', () => {
4+
describe.concurrent('ethereum.Value -> AssemblyScript', () => {
45
// Scalar values
56

67
test('address -> Address', () => {

packages/cli/src/codegen/util.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import { describe, expect, test } from 'vitest';
12
import { disambiguateNames, unrollTuple } from './util';
23

3-
describe('Codegen utilities', () => {
4+
describe.concurrent('Codegen utilities', () => {
45
test('Name disambiguation', () => {
56
expect(
67
disambiguateNames({

packages/cli/src/command-helpers/abi.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, expect, test } from 'vitest';
12
import { getStartBlockForContract } from './abi';
23

34
// An object with some test cases for contract deployment block numbers

packages/cli/src/command-helpers/compiler.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import { describe, expect, it } from 'vitest';
12
import { appendApiVersionForGraph } from './compiler';
23

3-
describe('appendApiVersionForGraph', () => {
4+
describe.concurrent('appendApiVersionForGraph', () => {
45
it('append /api/v0 to Prod URL with trailing slash', () => {
56
expect(appendApiVersionForGraph('https://api.thegraph.com/ipfs/')).toBe(
67
'https://api.thegraph.com/ipfs/api/v0',

0 commit comments

Comments
 (0)