Skip to content

Commit

Permalink
refactor: use execSync for tests (#207)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith authored Apr 4, 2019
1 parent c5fed7a commit 944aa05
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 29 deletions.
1 change: 0 additions & 1 deletion texttospeech/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
},
"devDependencies": {
"chai": "^4.2.0",
"execa": "^1.0.0",
"mocha": "^6.0.0"
},
"optionalDependencies": {
Expand Down
15 changes: 5 additions & 10 deletions texttospeech/test/audioProfile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,9 @@

const fs = require('fs');
const {assert} = require('chai');
const execa = require('execa');
const {execSync} = require('child_process');

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';
Expand All @@ -45,7 +40,7 @@ describe('audio profile', () => {

it('should synthesize Speech for Telephone Audio Profile', async () => {
assert.strictEqual(fs.existsSync(outputFile1), false);
const output = await exec(
const output = execSync(
`${cmd} synthesize '${text}' -f ${outputFile1} -e telephony-class-application`
);
assert.match(
Expand All @@ -57,7 +52,7 @@ describe('audio profile', () => {

it('should synthesize Speech for Home Theatre Audio Profile', async () => {
assert.strictEqual(fs.existsSync(outputFile2), false);
const output = await exec(
const output = execSync(
`${cmd} synthesize '${text}' -f ${outputFile2} -e large-home-entertainment-class-device`
);
assert.match(
Expand All @@ -69,7 +64,7 @@ describe('audio profile', () => {

it('should synthesize Speech for Car Audio Audio Profile', async () => {
assert.strictEqual(fs.existsSync(outputFile3), false);
const output = await exec(
const output = execSync(
`${cmd} synthesize '${text}' -f ${outputFile3} -e large-automotive-class-device`
);
assert.match(
Expand All @@ -81,7 +76,7 @@ describe('audio profile', () => {

it('should synthesize Speech for Watch Audio Profile', async () => {
assert.strictEqual(fs.existsSync(outputFile4), false);
const output = await exec(
const output = execSync(
`${cmd} synthesize '${text}' -f ${outputFile4} -e wearable-class-device`
);
assert.match(
Expand Down
4 changes: 2 additions & 2 deletions texttospeech/test/listVoices.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
'use strict';

const {assert} = require('chai');
const execa = require('execa');
const {execSync} = require('child_process');

const cmd = 'node listVoices.js';

describe('list voices', () => {
it('should list voices', async () => {
const {stdout} = await execa.shell(`${cmd} list-voices`);
const stdout = execSync(`${cmd} list-voices`);
assert.match(stdout, /SSML Voice Gender: FEMALE/);
assert.match(stdout, /Natural Sample Rate Hertz: 24000/);
});
Expand Down
4 changes: 2 additions & 2 deletions texttospeech/test/quickstart.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

const fs = require('fs');
const {assert} = require('chai');
const execa = require('execa');
const {execSync} = require('child_process');

const outputFile = 'output.mp3';

Expand All @@ -32,7 +32,7 @@ describe('quickstart', () => {

it('should synthesize speech to local mp3 file', async () => {
assert.strictEqual(fs.existsSync(outputFile), false);
const {stdout} = await execa.shell('node quickstart');
const stdout = execSync('node quickstart');
assert.match(stdout, /Audio content written to file: output.mp3/);
assert.ok(fs.existsSync(outputFile));
});
Expand Down
19 changes: 5 additions & 14 deletions texttospeech/test/synthesize.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,8 @@
const fs = require('fs');
const path = require('path');
const {assert} = require('chai');
const execa = require('execa');
const {execSync} = require('child_process');

const exec = async cmd => {
const res = await execa.shell(cmd);
assert.isEmpty(res.stderr);
return res.stdout;
};
const cmd = 'node synthesize.js';
const text = 'Hello there.';
const ssml = '<speak>Hello there.</speak>';
Expand All @@ -47,9 +42,7 @@ describe('synthesize', () => {

it('should synthesize audio from text', async () => {
assert.strictEqual(fs.existsSync(outputFile), false);
const output = await exec(
`${cmd} text '${text}' --outputFile ${outputFile}`
);
const output = execSync(`${cmd} text '${text}' --outputFile ${outputFile}`);
assert.match(
output,
new RegExp(`Audio content written to file: ${outputFile}`)
Expand All @@ -59,9 +52,7 @@ describe('synthesize', () => {

it('should synthesize audio from ssml', async () => {
assert.strictEqual(fs.existsSync(outputFile), false);
const output = await exec(
`${cmd} ssml "${ssml}" --outputFile ${outputFile}`
);
const output = execSync(`${cmd} ssml "${ssml}" --outputFile ${outputFile}`);
assert.match(
output,
new RegExp(`Audio content written to file: ${outputFile}`)
Expand All @@ -71,7 +62,7 @@ describe('synthesize', () => {

it('should synthesize audio from text file', async () => {
assert.strictEqual(fs.existsSync(outputFile), false);
const output = await exec(
const output = execSync(
`${cmd} text-file ${files[0].localPath} --outputFile ${outputFile}`
);
assert.match(
Expand All @@ -83,7 +74,7 @@ describe('synthesize', () => {

it('should synthesize audio from ssml file', async () => {
assert.strictEqual(fs.existsSync(outputFile), false);
const output = await exec(
const output = execSync(
`${cmd} ssml-file ${files[1].localPath} --outputFile ${outputFile}`
);
assert.match(
Expand Down

0 comments on commit 944aa05

Please sign in to comment.