From c7333f650b624b768fa7c427863d9b28b9529437 Mon Sep 17 00:00:00 2001 From: Alex Korzhikov Date: Sun, 20 Aug 2023 16:14:21 +0200 Subject: [PATCH] run tests with docker --- protoc-gen-graphql/package.json | 3 ++- protoc-gen-graphql/tests/index.spec.js | 6 ++--- protoc-gen-graphql/tests/util.js | 32 ++++---------------------- 3 files changed, 9 insertions(+), 32 deletions(-) diff --git a/protoc-gen-graphql/package.json b/protoc-gen-graphql/package.json index 00ac671..365e302 100644 --- a/protoc-gen-graphql/package.json +++ b/protoc-gen-graphql/package.json @@ -4,9 +4,10 @@ "description": "", "bin": "index.js", "scripts": { - "start": "../vendor/protoc-23.2-osx-aarch_64/bin/protoc --graphql_out=. ../books.proto", + "start": "protoc --graphql_out=. ../books.proto", "docker:build": "docker build -t local-protoc .", "docker:run": "docker run -it local-protoc bash", + "docker:test": "docker run -it local-protoc node --test ./tests/**", "test": "node --test ./tests/**" }, "keywords": [], diff --git a/protoc-gen-graphql/tests/index.spec.js b/protoc-gen-graphql/tests/index.spec.js index 262162e..c351ba8 100644 --- a/protoc-gen-graphql/tests/index.spec.js +++ b/protoc-gen-graphql/tests/index.spec.js @@ -7,10 +7,10 @@ describe("executes all test packages", (t) => { for (const dir of getTestDirs()) { it(`runs protoc in ${dir}`, async (t) => { runProtoc(dir); - assert.strictEqual(1, 1); - tmpDir = fs.readdirSync("/tmp"); - console.log(tmpDir); + actualDir = fs.readdirSync(dir); + assert.equal(actualDir.includes('schema.gql'), true, 'should produce schema file'); + assert.equal(actualDir.includes('debug.log'), true, 'should produce debug file'); }); } }); diff --git a/protoc-gen-graphql/tests/util.js b/protoc-gen-graphql/tests/util.js index db8d07a..c8fc017 100644 --- a/protoc-gen-graphql/tests/util.js +++ b/protoc-gen-graphql/tests/util.js @@ -2,14 +2,11 @@ // https://github.com/nodejs/node/pull/48856 const fs = require("node:fs"); const { join } = require("node:path"); -const { spawn } = require("node:child_process"); -const path = require("node:path"); -const mock = require("mock-fs"); +const { spawnSync } = require("node:child_process"); exports.getTestDirs = () => { // get all directories const testDirContent = fs.readdirSync(__dirname); - console.log(testDirContent); const testDirs = []; for (const dirItem of testDirContent) { @@ -23,29 +20,8 @@ exports.getTestDirs = () => { return testDirs; }; -exports.runProtoc = (dir) => { - mock({ - "/tmp": mock.load(dir, { recursive: false, lazy: false }), - '/tmp/protoc': mock.load(path.resolve(__dirname, '../../vendor/protoc-23.2-osx-aarch_64/bin/protoc')), - }); - - process.env.PATH = `${process.env.PATH}:/tmp` - const child = spawn("ls", ["-c", "/tmp", "-la"], { - cwd: process.cwd(), - env: { - PATH: process.env.PATH, - }, - }); - - child.stdout.on('data', function(data) { - console.log('PATH:', data.toString()); - }); - - child.stderr.on('data', function(data) { - console.error('Error:', data.toString()); - }); - - child.on('exit', function(code) { - console.log('Child process exited with code', code); +exports.runProtoc = (cwd) => { + spawnSync("protoc", ["--graphql_out", ".", "books.proto"], { + cwd, }); };