diff --git a/packages/google-cloud-translate/samples/.eslintrc.yml b/packages/google-cloud-translate/samples/.eslintrc.yml index 282535f55f6..0aa37ac630e 100644 --- a/packages/google-cloud-translate/samples/.eslintrc.yml +++ b/packages/google-cloud-translate/samples/.eslintrc.yml @@ -1,3 +1,4 @@ --- rules: no-console: off + node/no-missing-require: off diff --git a/packages/google-cloud-translate/samples/package.json b/packages/google-cloud-translate/samples/package.json index 944557f21ba..565009624d6 100644 --- a/packages/google-cloud-translate/samples/package.json +++ b/packages/google-cloud-translate/samples/package.json @@ -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", @@ -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" diff --git a/packages/google-cloud-translate/samples/test/quickstart.test.js b/packages/google-cloud-translate/samples/test/quickstart.test.js new file mode 100644 index 00000000000..36efd92428a --- /dev/null +++ b/packages/google-cloud-translate/samples/test/quickstart.test.js @@ -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: Привет, мир!')); + }); +});