Skip to content

Commit

Permalink
run tests with docker
Browse files Browse the repository at this point in the history
  • Loading branch information
korzio committed Aug 20, 2023
1 parent 74cc78f commit c7333f6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 32 deletions.
3 changes: 2 additions & 1 deletion protoc-gen-graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [],
Expand Down
6 changes: 3 additions & 3 deletions protoc-gen-graphql/tests/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
}
});
32 changes: 4 additions & 28 deletions protoc-gen-graphql/tests/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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,
});
};

0 comments on commit c7333f6

Please sign in to comment.