diff --git a/packages/google-cloud-texttospeech/samples/.eslintrc.yml b/packages/google-cloud-texttospeech/samples/.eslintrc.yml index 282535f55f6..0aa37ac630e 100644 --- a/packages/google-cloud-texttospeech/samples/.eslintrc.yml +++ b/packages/google-cloud-texttospeech/samples/.eslintrc.yml @@ -1,3 +1,4 @@ --- rules: no-console: off + node/no-missing-require: off diff --git a/packages/google-cloud-texttospeech/samples/package.json b/packages/google-cloud-texttospeech/samples/package.json index 3315760a889..2304ad8cce7 100644 --- a/packages/google-cloud-texttospeech/samples/package.json +++ b/packages/google-cloud-texttospeech/samples/package.json @@ -1,22 +1,25 @@ { "name": "nodejs-docs-samples-text-to-speech", - "version": "0.0.1", "private": true, "license": "Apache-2.0", "author": "Google Inc.", "repository": "googleapis/nodejs-text-to-speech", + "files": [ + "*.js" + ], "engines": { "node": ">=8" }, "scripts": { - "test": "mocha system-test/*.test.js --timeout=600000" + "test": "mocha --timeout=60000" }, "dependencies": { "@google-cloud/text-to-speech": "^0.4.0", "yargs": "^12.0.0" }, "devDependencies": { - "@google-cloud/nodejs-repo-tools": "^3.0.0", + "chai": "^4.2.0", + "execa": "^1.0.0", "mocha": "^5.2.0" }, "optionalDependencies": { diff --git a/packages/google-cloud-texttospeech/samples/test/quickstart.test.js b/packages/google-cloud-texttospeech/samples/test/quickstart.test.js new file mode 100644 index 00000000000..09bf7c22ac7 --- /dev/null +++ b/packages/google-cloud-texttospeech/samples/test/quickstart.test.js @@ -0,0 +1,39 @@ +/** + * 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 fs = require('fs'); +const {assert} = require('chai'); +const execa = require('execa'); + +const outputFile = 'output.mp3'; + +describe('quickstart', () => { + after(() => { + try { + fs.unlinkSync(outputFile); + } catch (err) { + // Ignore error + } + }); + + it('should synthesize speech to local mp3 file', async () => { + assert.strictEqual(fs.existsSync(outputFile), false); + const {stdout} = await execa.shell('node quickstart'); + assert.match(stdout, /Audio content written to file: output.mp3/); + assert.ok(fs.existsSync(outputFile)); + }); +});