Skip to content

Commit

Permalink
test: fix flakey json output test
Browse files Browse the repository at this point in the history
  • Loading branch information
maxjeffos committed Mar 1, 2021
1 parent 4848b7e commit 69cd590
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 25 deletions.
8 changes: 4 additions & 4 deletions .circleci/config.yml
Expand Up @@ -500,7 +500,7 @@ workflows:
- test-windows:
name: Windows, Node 12 - Packages, Jest, Acceptance, System tests
context: nodejs-install
node_version: '12.16.2'
node_version: '12.21.0'
jest_tests: true
acceptance_tests: true
system_tests: true
Expand All @@ -510,7 +510,7 @@ workflows:
- test-windows:
name: Windows, Node 12 - "Root" tap tests
context: nodejs-install
node_version: '12.16.2'
node_version: '12.21.0'
root_tap_tests: true
requires:
- Regression Test
Expand Down Expand Up @@ -552,7 +552,7 @@ workflows:
- test-linux:
name: Linux, Node 12 - Packages, Jest, Acceptance, System tests
context: nodejs-install
node_version: '12.16.2'
node_version: '12.21.0'
jest_tests: true
acceptance_tests: true
system_tests: true
Expand All @@ -562,7 +562,7 @@ workflows:
- test-linux:
name: Linux, Node 12 - "Root" tap tests
context: nodejs-install
node_version: '12.16.2'
node_version: '12.21.0'
root_tap_tests: true
requires:
- Regression Test
Expand Down
8 changes: 4 additions & 4 deletions package.json
Expand Up @@ -38,7 +38,7 @@
"test:acceptance": "tap test/acceptance/**/*.test.* test/acceptance/*.test.* -Rspec --timeout=300 --node-arg=-r --node-arg=ts-node/register",
"test:acceptance-windows": "tap test/acceptance/**/*.test.* -Rspec --timeout=300 --node-arg=-r --node-arg=ts-node/register",
"test:system": "tap test/system/*.test.* -Rspec --timeout=300 --node-arg=-r --node-arg=ts-node/register",
"test:jest": "jest test/*",
"test:jest": "jest --runInBand test/*",
"test:packages-unit": "jest packages/**/test/unit/*.spec.ts",
"test:packages-acceptance": "jest packages/**/test/acceptance/*.spec.ts",
"test:test": "tap test/*.test.* -Rspec --timeout=300 --node-arg=-r --node-arg=ts-node/register",
Expand Down Expand Up @@ -131,7 +131,7 @@
"devDependencies": {
"@types/agent-base": "^4.2.1",
"@types/diff": "^3.5.2",
"@types/jest": "^25.2.3",
"@types/jest": "^26.0.20",
"@types/lodash": "^4.14.161",
"@types/needle": "^2.0.4",
"@types/node": "^10.0.0",
Expand All @@ -143,7 +143,7 @@
"@typescript-eslint/parser": "^2.0.0",
"eslint": "6.8.0",
"eslint-config-prettier": "^6.1.0",
"jest": "^25.5.4",
"jest": "^26.6.3",
"lodash": "^4.17.20",
"lodash.countby": "^4.6.0",
"lodash.every": "^4.6.0",
Expand All @@ -157,7 +157,7 @@
"sinon": "^4.0.0",
"tap": "^12.6.1",
"tape": "^4.0.0",
"ts-jest": "^25.5.1",
"ts-jest": "^26.5.2",
"ts-node": "^8.0.0",
"tslint": "^5.14.0",
"typescript": "^3.4.1"
Expand Down
29 changes: 12 additions & 17 deletions test/cli-json-file-output.spec.ts
Expand Up @@ -20,21 +20,18 @@ describe('test --json-file-output ', () => {
);
it(
'`can save JSON output to file while sending human readable output to stdout`',
async (done) => {
return exec(
`node ${main} test ${noVulnsProjectPath} --json-file-output=snyk-direct-json-test-output.json`,
async (err, stdout) => {
(done) => {
const jsonOutputFilename = `${uuidv4()}.json`;
exec(
`node ${main} test ${noVulnsProjectPath} --json-file-output=${jsonOutputFilename}`,
(err, stdout) => {
if (err) {
throw err;
}
// give file a little time to be finished to be written
await new Promise((r) => setTimeout(r, 5000));

expect(stdout).toMatch('Organization:');
const outputFileContents = readFileSync(
'snyk-direct-json-test-output.json',
'utf-8',
);
unlinkSync('./snyk-direct-json-test-output.json');
const outputFileContents = readFileSync(jsonOutputFilename, 'utf-8');
unlinkSync(`./${jsonOutputFilename}`);
const jsonObj = JSON.parse(outputFileContents);
const okValue = jsonObj.ok as boolean;
expect(okValue).toBeTruthy();
Expand All @@ -48,20 +45,18 @@ describe('test --json-file-output ', () => {
it(
'`test --json-file-output produces same JSON output as normal JSON output to stdout`',
(done) => {
const jsonOutputFilename = `${uuidv4()}.json`;
return exec(
`node ${main} test ${noVulnsProjectPath} --json --json-file-output=snyk-direct-json-test-output.json`,
`node ${main} test ${noVulnsProjectPath} --json --json-file-output=${jsonOutputFilename}`,
async (err, stdout) => {
if (err) {
throw err;
}
// give file a little time to be finished to be written
await new Promise((r) => setTimeout(r, 3000));
const stdoutJson = stdout;
const outputFileContents = readFileSync(
'snyk-direct-json-test-output.json',
'utf-8',
);
unlinkSync('./snyk-direct-json-test-output.json');
const outputFileContents = readFileSync(jsonOutputFilename, 'utf-8');
unlinkSync(`./${jsonOutputFilename}`);
expect(stdoutJson).toEqual(outputFileContents);
done();
},
Expand Down

0 comments on commit 69cd590

Please sign in to comment.