Skip to content

Commit

Permalink
refactor: use execSync for tests (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith committed Apr 5, 2019
1 parent 69913c6 commit b1b9eea
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/google-cloud-translate/samples/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
rules:
no-console: off
node/no-missing-require: off
3 changes: 1 addition & 2 deletions packages/google-cloud-translate/samples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"node": ">=8"
},
"scripts": {
"test": "mocha system-test --recursive --timeout 90000"
"test": "mocha --recursive --timeout 90000"
},
"dependencies": {
"@google-cloud/translate": "^3.0.0",
Expand All @@ -17,7 +17,6 @@
},
"devDependencies": {
"chai": "^4.2.0",
"execa": "^1.0.0",
"@google-cloud/storage": "^2.4.3",
"mocha": "^6.0.0",
"uuid": "^3.3.2"
Expand Down
32 changes: 32 additions & 0 deletions packages/google-cloud-translate/samples/test/quickstart.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Copyright 2017, Google, Inc.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

const {assert} = require('chai');
const cp = require('child_process');
const path = require('path');

const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});

const cwd = path.join(__dirname, '..');
const projectId = process.env.GCLOUD_PROJECT;

describe('quickstart sample tests', () => {
it('should translate a string', async () => {
const stdout = execSync(`node quickstart ${projectId}`, {cwd});
assert.match(stdout, new RegExp('Translation: Привет, мир!'));
});
});

0 comments on commit b1b9eea

Please sign in to comment.