Skip to content

Commit c031aab

Browse files
authored
Merge pull request #216 from proto-graphql/izumin5210/e2e
New e2e testing
2 parents 8ff3f95 + 831f8e7 commit c031aab

File tree

199 files changed

+4667
-3911
lines changed

Some content is hidden

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

199 files changed

+4667
-3911
lines changed

.changeset/wild-toes-pull.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@proto-graphql/e2e": patch
3+
"@testapis/proto": patch
4+
"protoc-gen-nexus": patch
5+
"protoc-gen-pothos": patch
6+
---
7+
8+
new E2E testing

.github/workflows/ci.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
base-path: packages/protoc-gen-nexus
2929

3030

31-
test-integration:
31+
test-e2e:
3232

3333
runs-on: ubuntu-latest
3434

@@ -40,5 +40,6 @@ jobs:
4040
uses: actions/setup-node@v1
4141
with:
4242
node-version: 14.x
43+
- uses: bufbuild/buf-setup-action@v1
4344
- run: yarn --frozen-lockfile
44-
- run: yarn test:integration
45+
- run: yarn test:e2e

buf.work.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version: v1
2+
directories:
3+
- packages/@testapis/proto/src

e2e/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/tests/__generated__/*
2+
/tests/*/__generated__/*
3+
!/tests/*/__generated__/schema.graphql

e2e/buf.gen.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
version: v1
2+
plugins:
3+
- name: nexus
4+
path: ../packages/protoc-gen-nexus/bin/protoc-gen-nexus
5+
out: tests/__generated__/nexus/protobufjs
6+
opt:
7+
- use_protobufjs
8+
- import_prefix=@testapis/node/lib/
9+
- name: nexus
10+
path: ../packages/protoc-gen-nexus/bin/protoc-gen-nexus
11+
out: tests/__generated__/nexus/google-protobuf
12+
opt:
13+
- import_prefix=@testapis/node-native/lib/
14+
- name: pothos
15+
path: ../packages/protoc-gen-pothos/bin/protoc-gen-pothos
16+
out: tests/__generated__/pothos/ts-proto
17+
opt:
18+
- import_prefix=@testapis/ts-proto/lib/
19+
- pothos_builder_path=@/builder
20+
- name: pothos
21+
path: ../packages/protoc-gen-pothos/bin/protoc-gen-pothos
22+
out: tests/__generated__/pothos/ts-proto-with-forcelong-number
23+
opt:
24+
- import_prefix=@testapis/ts-proto-with-forcelong-number/lib/
25+
- pothos_builder_path=@/builder
26+
- long_number=Int

e2e/jest.config.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// eslint-disable-next-line @typescript-eslint/no-var-requires
2+
const path = require("path");
3+
4+
module.exports = {
5+
// eslint-disable-next-line @typescript-eslint/no-var-requires
6+
projects: require("glob")
7+
.sync("./tests/*/tsconfig.json")
8+
.map((tsconfigPath) => {
9+
return {
10+
preset: "ts-jest",
11+
testEnvironment: "node",
12+
rootDir: path.dirname(tsconfigPath),
13+
moduleNameMapper: {
14+
"^@/(.*)$": "<rootDir>/$1",
15+
},
16+
};
17+
}),
18+
globals: {
19+
"ts-jest": {
20+
// typecheck on other process
21+
diagnostics: false,
22+
},
23+
},
24+
};

e2e/package.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "@proto-graphql/e2e",
3+
"version": "0.0.1",
4+
"description": "E2E tests",
5+
"private": true,
6+
"devDependencies": {
7+
"@testapis/node": "^0.5.0",
8+
"@testapis/node-native": "^0.5.1",
9+
"@testapis/ts-proto": "^0.5.1",
10+
"@testapis/ts-proto-with-forcelong-number": "^0.6.0",
11+
"protoc-gen-nexus": "^0.5.1",
12+
"protoc-gen-pothos": "^0.2.0",
13+
"tsconfig-paths": "^4.1.0"
14+
},
15+
"scripts": {
16+
"test:setup": "./setupTests.mjs",
17+
"test:typecheck": "tsc -b tsconfig.json",
18+
"test:jest": "jest",
19+
"test:schema": "git diff --exit-code tests/**/schema.graphql",
20+
"test:e2e": "yarn test:setup && yarn test:typecheck && yarn test:jest && yarn test:schema"
21+
}
22+
}

e2e/setupTests.mjs

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/usr/bin/env node
2+
/* eslint-disable @typescript-eslint/no-var-requires */
3+
4+
import { exec as _exec } from "child_process";
5+
import { mkdir, readFile, rm, writeFile } from "fs/promises";
6+
import { basename, join, relative } from "path";
7+
import { promisify } from "util";
8+
9+
const exec = promisify(_exec);
10+
const header = `// Code generated by ${basename(import.meta.url)}. DO NOT EDIT.`;
11+
const testsDir = "tests";
12+
13+
/**
14+
* @param {{ target: "nexus" | "pothos", proto: { package: String, lib: String } } opts
15+
*/
16+
function getTestPath(opts) {
17+
return `${testsDir}/${[opts.target, opts.proto.package.replace("/", "-"), opts.proto.lib].join("--")}`;
18+
}
19+
20+
/**
21+
* @param {{ target: "nexus" | "pothos", proto: { package: String, lib: String } } opts
22+
*/
23+
async function setupTest(opts) {
24+
const path = getTestPath(opts);
25+
const genDir = join(path, "__generated__");
26+
const tsconfigPath = join(path, "tsconfig.json");
27+
const schemaPath = join(path, "schema.ts");
28+
29+
await rm(genDir, { recursive: true, force: true });
30+
await mkdir(genDir, { recursive: true });
31+
32+
const tsconfig = {
33+
extends: "../../tsconfig.base.json",
34+
compilerOptions: {
35+
baseUrl: ".",
36+
paths: {
37+
"@/*": ["./*"],
38+
},
39+
},
40+
include: [
41+
".",
42+
relative(path, "./src"),
43+
relative(
44+
path,
45+
[testsDir, "__generated__", opts.target, opts.proto.lib, "testapis", ...opts.proto.package.split("/")].join("/")
46+
),
47+
].map((p) => `${p}/**/*`),
48+
};
49+
50+
await writeFile(tsconfigPath, `${header}\n${JSON.stringify(tsconfig, undefined, 2)}`, "utf-8");
51+
52+
await exec(`yarn ts-node --transpile-only --require tsconfig-paths/register --project ${tsconfigPath} ${schemaPath}`);
53+
}
54+
55+
async function setupTests() {
56+
/** @type {{ tests: { target: "nexus" | "pothos", proto: { package: String, lib: String} }[] } */
57+
const config = JSON.parse(await readFile("tests.json", "utf-8"));
58+
59+
await Promise.all(config.tests.map(setupTest));
60+
await writeFile(
61+
"tsconfig.json",
62+
`${header}\n${JSON.stringify(
63+
{
64+
files: [],
65+
references: config.tests.map((tt) => ({ path: getTestPath(tt) })),
66+
},
67+
undefined,
68+
2
69+
)}`,
70+
"utf-8"
71+
);
72+
}
73+
74+
async function setupProtoNexus() {
75+
await rm(join(testsDir, "__generated__"), { recursive: true, force: true });
76+
await exec(`buf generate ${join("..", "packages", "@testapis", "proto", "src")}`);
77+
}
78+
79+
async function main() {
80+
await setupProtoNexus();
81+
await setupTests();
82+
}
83+
84+
await main();

e2e/src/makeTestSchema.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { makeSchema } from "nexus";
2+
import * as path from "path";
3+
4+
export function makeTestSchema({ rootDir, types }: { rootDir: string; types: any }) {
5+
const schema = makeSchema({
6+
types,
7+
outputs: {
8+
schema: path.join(rootDir, "__generated__", "schema.graphql"),
9+
typegen: path.join(rootDir, "__generated__", "typings.ts"),
10+
},
11+
shouldGenerateArtifacts: true,
12+
features: {
13+
abstractTypeStrategies: {
14+
isTypeOf: true,
15+
},
16+
},
17+
});
18+
19+
return schema;
20+
}

e2e/src/printGraphqlSchema.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { mkdirSync, writeFileSync } from "fs";
2+
import { GraphQLSchema, printSchema } from "graphql";
3+
import { join } from "path";
4+
5+
export function printGraphqlSchema({ rootDir, schema }: { rootDir: string; schema: GraphQLSchema }) {
6+
mkdirSync(join(rootDir, "__generated__"), { recursive: true });
7+
writeFileSync(join(rootDir, "__generated__", "schema.graphql"), printSchema(schema), "utf-8");
8+
}

0 commit comments

Comments
 (0)