From 69b58b114c1cd342e2baa6ae33bc46f6ab5ca90c Mon Sep 17 00:00:00 2001 From: Justin Beckwith Date: Thu, 4 Apr 2019 21:15:11 -0700 Subject: [PATCH] refactor: use execSync for tests (#127) --- asset/snippets/package.json | 3 +-- asset/snippets/{system-test => test}/.eslintrc.yml | 0 .../{system-test => test}/quickstart.test.js | 14 +++++--------- 3 files changed, 6 insertions(+), 11 deletions(-) rename asset/snippets/{system-test => test}/.eslintrc.yml (100%) rename asset/snippets/{system-test => test}/quickstart.test.js (84%) diff --git a/asset/snippets/package.json b/asset/snippets/package.json index 38c6c9eea34..527c478b300 100644 --- a/asset/snippets/package.json +++ b/asset/snippets/package.json @@ -12,7 +12,7 @@ "repository": "googleapis/nodejs-asset", "private": true, "scripts": { - "test": "mocha system-test --timeout 20000" + "test": "mocha --timeout 20000" }, "dependencies": { "@google-cloud/asset": "^0.3.0", @@ -22,7 +22,6 @@ }, "devDependencies": { "chai": "^4.2.0", - "execa": "^1.0.0", "mocha": "^6.0.0" } } diff --git a/asset/snippets/system-test/.eslintrc.yml b/asset/snippets/test/.eslintrc.yml similarity index 100% rename from asset/snippets/system-test/.eslintrc.yml rename to asset/snippets/test/.eslintrc.yml diff --git a/asset/snippets/system-test/quickstart.test.js b/asset/snippets/test/quickstart.test.js similarity index 84% rename from asset/snippets/system-test/quickstart.test.js rename to asset/snippets/test/quickstart.test.js index e04aa190eab..688490a1cb5 100644 --- a/asset/snippets/system-test/quickstart.test.js +++ b/asset/snippets/test/quickstart.test.js @@ -16,14 +16,13 @@ 'use strict'; const {assert} = require('chai'); -const path = require('path'); const uuid = require('uuid'); -const execa = require('execa'); +const cp = require('child_process'); const {Storage} = require('@google-cloud/storage'); -const cwd = path.join(__dirname, '..'); -const cmd = 'node quickstart.js'; +const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); +const cmd = 'node quickstart.js'; const storage = new Storage(); const bucketName = `asset-nodejs-${uuid.v4()}`; const bucket = storage.bucket(bucketName); @@ -39,7 +38,7 @@ describe('quickstart sample tests', () => { it('should export assets to specified path', async () => { const dumpFilePath = `gs://${bucketName}/my-assets.txt`; - await execa.shell(`${cmd} export-assets ${dumpFilePath}`, {cwd}); + execSync(`${cmd} export-assets ${dumpFilePath}`); const file = await bucket.file('my-assets.txt'); const exists = await file.exists(); assert.ok(exists); @@ -48,10 +47,7 @@ describe('quickstart sample tests', () => { it('should get assets history successfully', async () => { const assetName = `//storage.googleapis.com/${bucketName}`; - const {stdout} = await execa.shell( - `${cmd} batch-get-history ${assetName}`, - {cwd} - ); + const stdout = execSync(`${cmd} batch-get-history ${assetName}`); assert.match(stdout, new RegExp(assetName)); }); });