Skip to content

Commit

Permalink
refactor: use execSync for tests (#286)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith authored and Ace Nassri committed Nov 21, 2022
1 parent fbd3dab commit df35469
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
1 change: 0 additions & 1 deletion compute/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
},
"devDependencies": {
"chai": "^4.2.0",
"execa": "^1.0.0",
"mocha": "^6.0.0",
"proxyquire": "^2.0.1",
"uuid": "^3.2.1"
Expand Down
17 changes: 9 additions & 8 deletions compute/test/samples.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,19 @@
'use strict';

const uuid = require('uuid');
const execa = require('execa');
const cp = require('child_process');
const {assert} = require('chai');
const Compute = require('@google-cloud/compute');

const exec = async cmd => (await execa.shell(cmd)).stdout;
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});

const compute = new Compute();

describe('quickstart', () => {
const name = `gcloud-ubuntu-${uuid.v4().split('-')[0]}`;
after(async () => deleteVM(name));
it('should run the quickstart', async () => {
const output = await exec(`node quickstart ${name}`);
const output = execSync(`node quickstart ${name}`);
assert.match(output, /Virtual machine created!/);
});
});
Expand All @@ -36,17 +37,17 @@ describe('lifecycle', async () => {
const name = `gcloud-ubuntu-${uuid.v4().split('-')[0]}`;

it('should create a VM', async () => {
const output = await exec(`node createVM ${name}`);
const output = execSync(`node createVM ${name}`);
assert.match(output, /Virtual machine created!/);
});

it('should list the VMs', async () => {
const output = await exec('node listVMs');
const output = execSync('node listVMs');
assert.match(output, /Found \d+ VMs!/);
});

it('should delete the VM', async () => {
const output = await exec(`node deleteVM ${name}`);
const output = execSync(`node deleteVM ${name}`);
assert.match(output, /VM deleted!/);
});
});
Expand All @@ -55,8 +56,8 @@ describe('start-up script', async () => {
const name = `gcloud-apache-${uuid.v4().split('-')[0]}`;
after(async () => deleteVM(name));
it('should create vm with startup script', async () => {
const output = await exec(`node startupScript ${name}`);
assert.match(output, /created succesfully$/);
const output = execSync(`node startupScript ${name}`);
assert.match(output, /created succesfully/);
});
});

Expand Down

0 comments on commit df35469

Please sign in to comment.