Skip to content

Commit

Permalink
fix: fix sample tests (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith authored and Ace Nassri committed Nov 17, 2022
1 parent 5d36e18 commit 532d97b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 21 deletions.
13 changes: 3 additions & 10 deletions asset/snippets/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "@google-cloud/asset-samples",
"description": "Samples for the Cloud Asset API Client Library for Node.js.",
"version": "0.0.1",
"license": "Apache-2.0",
"author": "Google Inc.",
"engines": {
Expand All @@ -12,24 +11,18 @@
],
"repository": "googleapis/nodejs-asset",
"private": true,
"nyc": {
"exclude": [
"**/*.test.js"
]
},
"scripts": {
"test": "mocha system-test --timeout 20000"
},
"dependencies": {
"@google-cloud/asset": "^0.1.1",
"@google-cloud/storage": "^2.3.0",
"express": "^4.16.4",
"uuid": "^3.3.2",
"yargs": "^12.0.0"
},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "^3.0.0",
"mocha": "^5.2.0",
"sinon": "^7.0.0"
"chai": "^4.2.0",
"execa": "^1.0.0",
"mocha": "^5.2.0"
}
}
19 changes: 8 additions & 11 deletions asset/snippets/system-test/quickstart.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,20 @@

'use strict';

const assert = require('assert');
const {assert} = require('chai');
const path = require('path');
const tools = require('@google-cloud/nodejs-repo-tools');
const uuid = require('uuid');
const execa = require('execa');
const {Storage} = require('@google-cloud/storage');

const cwd = path.join(__dirname, '..');
const cmd = 'node quickstart.js';

const {Storage} = require('@google-cloud/storage');

const storage = new Storage();
const bucketName = `asset-nodejs-${uuid.v4()}`;
const bucket = storage.bucket(bucketName);

describe('quickstart sample tests', () => {
before(tools.checkCredentials);
before(async () => {
await bucket.create();
});
Expand All @@ -40,7 +39,7 @@ describe('quickstart sample tests', () => {

it('should export assets to specified path', async () => {
const dumpFilePath = `gs://${bucketName}/my-assets.txt`;
await tools.runAsyncWithIO(`${cmd} export-assets ${dumpFilePath}`, cwd);
await execa.shell(`${cmd} export-assets ${dumpFilePath}`, {cwd});
const file = await bucket.file('my-assets.txt');
const exists = await file.exists();
assert.ok(exists);
Expand All @@ -49,12 +48,10 @@ describe('quickstart sample tests', () => {

it('should get assets history successfully', async () => {
const assetName = `//storage.googleapis.com/${bucketName}`;
const output = await tools.runAsyncWithIO(
const {stdout} = await execa.shell(
`${cmd} batch-get-history ${assetName}`,
cwd
{cwd}
);
if (output.stdout) {
assert.ok(output.stdout.includes(assetName));
}
assert.match(stdout, new RegExp(assetName));
});
});

0 comments on commit 532d97b

Please sign in to comment.