Skip to content

Commit

Permalink
refactor: modernize the sample tests (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith authored Dec 26, 2018
1 parent ca6e511 commit a9010d8
Show file tree
Hide file tree
Showing 9 changed files with 219 additions and 206 deletions.
1 change: 1 addition & 0 deletions texttospeech/.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
9 changes: 6 additions & 3 deletions texttospeech/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
85 changes: 0 additions & 85 deletions texttospeech/system-test/audioProfile.test.js

This file was deleted.

85 changes: 0 additions & 85 deletions texttospeech/system-test/synthesize.test.js

This file was deleted.

File renamed without changes.
93 changes: 93 additions & 0 deletions texttospeech/test/audioProfile.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/**
* Copyright 2018, 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 cmd = 'node audioProfile.js';
const exec = async cmd => {
const res = await execa.shell(cmd);
assert.isEmpty(res.stderr);
return res.stdout;
};
const text = 'Hello Everybody! This is an Audio Profile Optimized Sound Byte.';
const outputFile1 = 'phonetest.mp3';
const outputFile2 = 'homeTheatreTest.mp3';
const outputFile3 = 'carAudioTest.mp3';
const outputFile4 = 'watchAudioTest.mp3';

describe('audio profile', () => {
after(() => {
function unlink(outputFile) {
try {
fs.unlinkSync(outputFile);
} catch (err) {
// Ignore error
}
}
[outputFile1, outputFile2, outputFile3, outputFile4].map(unlink);
});

it('should synthesize Speech for Telephone Audio Profile', async () => {
assert.strictEqual(fs.existsSync(outputFile1), false);
const output = await exec(
`${cmd} synthesize '${text}' -f ${outputFile1} -e telephony-class-application`
);
assert.match(
output,
new RegExp(`Audio content written to file: ${outputFile1}`)
);
assert.ok(fs.existsSync(outputFile1));
});

it('should synthesize Speech for Home Theatre Audio Profile', async () => {
assert.strictEqual(fs.existsSync(outputFile2), false);
const output = await exec(
`${cmd} synthesize '${text}' -f ${outputFile2} -e large-home-entertainment-class-device`
);
assert.match(
output,
new RegExp(`Audio content written to file: ${outputFile2}`)
);
assert.ok(fs.existsSync(outputFile2));
});

it('should synthesize Speech for Car Audio Audio Profile', async () => {
assert.strictEqual(fs.existsSync(outputFile3), false);
const output = await exec(
`${cmd} synthesize '${text}' -f ${outputFile3} -e large-automotive-class-device`
);
assert.match(
output,
new RegExp(`Audio content written to file: ${outputFile3}`)
);
assert.ok(fs.existsSync(outputFile3));
});

it('should synthesize Speech for Watch Audio Profile', async () => {
assert.strictEqual(fs.existsSync(outputFile4), false);
const output = await exec(
`${cmd} synthesize '${text}' -f ${outputFile4} -e wearable-class-device`
);
assert.match(
output,
new RegExp(`Audio content written to file: ${outputFile4}`)
);
assert.ok(fs.existsSync(outputFile4));
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,17 @@
* limitations under the License.
*/

/* eslint-disable */

'use strict';

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

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

before(tools.checkCredentials);

it('should list voices', async () => {
const output = await tools.runAsync(`${cmd} list-voices`, cwd);
assert.ok(output.includes('SSML Voice Gender: FEMALE'));
assert.ok(output.includes('Natural Sample Rate Hertz: 24000'));
describe('list voices', () => {
it('should list voices', async () => {
const {stdout} = await execa.shell(`${cmd} list-voices`);
assert.match(stdout, /SSML Voice Gender: FEMALE/);
assert.match(stdout, /Natural Sample Rate Hertz: 24000/);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,27 @@
* limitations under the License.
*/

/* eslint-disable */

'use strict';

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

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

before(tools.stubConsole);
after(() => {
tools.restoreConsole();
try {
fs.unlinkSync(outputFile);
} catch(err) {
// Ignore error
}
});
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 output = await tools.runAsync(`${cmd}`, cwd);
assert.ok(output.includes('Audio content written to file: output.mp3'));
assert.ok(fs.existsSync(outputFile));
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));
});
});
Loading

0 comments on commit a9010d8

Please sign in to comment.