Skip to content

Commit

Permalink
refactor(samples): convert sample tests from ava to mocha (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
nareshqlogic authored and JustinBeckwith committed Nov 23, 2018
1 parent 5cb93dd commit 36ae426
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 96 deletions.
4 changes: 2 additions & 2 deletions texttospeech/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"node": ">=8"
},
"scripts": {
"test": "ava -T 1m --verbose system-test/*.test.js"
"test": "mocha system-test/*.test.js --timeout=600000"
},
"dependencies": {
"@google-cloud/text-to-speech": "^0.3.0",
Expand All @@ -18,7 +18,7 @@
},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "^3.0.0",
"ava": "^0.25.0"
"mocha": "^5.2.0"
},
"optionalDependencies": {
"canvas": "^2.0.0"
Expand Down
4 changes: 4 additions & 0 deletions texttospeech/system-test/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
env:
mocha: true

79 changes: 42 additions & 37 deletions texttospeech/system-test/audioProfile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,64 +17,69 @@

'use strict';

const fs = require(`fs`);
const path = require(`path`);
const test = require(`ava`);
const tools = require(`@google-cloud/nodejs-repo-tools`);
const fs = require('fs');
const path = require('path');
const assert = require('assert');
const tools = require('@google-cloud/nodejs-repo-tools');

const cmd = `node audioProfile.js`;
const cwd = path.join(__dirname, `..`);
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`;
const cmd = 'node audioProfile.js';
const cwd = path.join(__dirname, '..');
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';

test.before(tools.checkCredentials);
before(tools.checkCredentials);

test.after(async () => {
await fs.unlink(outputFile1);
await fs.unlink(outputFile2);
await fs.unlink(outputFile3);
await fs.unlink(outputFile4);
after(() => {
function unlink(outputFile) {
try {
fs.unlinkSync(outputFile);
} catch(err) {
// Ignore error
}
}

[outputFile1, outputFile2, outputFile3, outputFile4].map(unlink);
});

test(`Should synthesize Speech for Telephone Audio Profile`, async t => {
t.false(fs.existsSync(outputFile1));
it('Should synthesize Speech for Telephone Audio Profile', async () => {
assert.strictEqual(fs.existsSync(outputFile1), false);
const output = await tools.runAsync(
`${cmd} synthesize '${text}' -f '${outputFile1}' -e telephony-class-application`,
`${cmd} synthesize '${text}' -f ${outputFile1} -e telephony-class-application`,
cwd
);
t.true(output.includes(`Audio content written to file: ${outputFile1}`));
t.true(fs.existsSync(outputFile1));
assert.ok(output.includes(`Audio content written to file: ${outputFile1}`));
assert.ok(fs.existsSync(outputFile1));
});

test(`Should synthesize Speech for Home Theatre Audio Profile`, async t => {
t.false(fs.existsSync(outputFile2));
it('Should synthesize Speech for Home Theatre Audio Profile', async () => {
assert.strictEqual(fs.existsSync(outputFile2), false);
const output = await tools.runAsync(
`${cmd} synthesize '${text}' -f '${outputFile2}' -e large-home-entertainment-class-device`,
`${cmd} synthesize '${text}' -f ${outputFile2} -e large-home-entertainment-class-device`,
cwd
);
t.true(output.includes(`Audio content written to file: ${outputFile2}`));
t.true(fs.existsSync(outputFile2));
assert.ok(output.includes(`Audio content written to file: ${outputFile2}`));
assert.ok(fs.existsSync(outputFile2));
});

test(`Should synthesize Speech for Car Audio Audio Profile`, async t => {
t.false(fs.existsSync(outputFile3));
it('Should synthesize Speech for Car Audio Audio Profile', async () => {
assert.strictEqual(fs.existsSync(outputFile3), false);
const output = await tools.runAsync(
`${cmd} synthesize '${text}' -f '${outputFile3}' -e large-automotive-class-device`,
`${cmd} synthesize '${text}' -f ${outputFile3} -e large-automotive-class-device`,
cwd
);
t.true(output.includes(`Audio content written to file: ${outputFile3}`));
t.true(fs.existsSync(outputFile3));
assert.ok(output.includes(`Audio content written to file: ${outputFile3}`));
assert.ok(fs.existsSync(outputFile3));
});

test(`should synthesize Speech for Watch Audio Profile`, async t => {
t.false(fs.existsSync(outputFile4));
it('should synthesize Speech for Watch Audio Profile', async () => {
assert.strictEqual(fs.existsSync(outputFile4), false);
const output = await tools.runAsync(
`${cmd} synthesize '${text}' -f '${outputFile4}' -e wearable-class-device`,
`${cmd} synthesize '${text}' -f ${outputFile4} -e wearable-class-device`,
cwd
);
t.true(output.includes(`Audio content written to file: ${outputFile4}`));
t.true(fs.existsSync(outputFile4));
assert.ok(output.includes(`Audio content written to file: ${outputFile4}`));
assert.ok(fs.existsSync(outputFile4));
});
18 changes: 9 additions & 9 deletions texttospeech/system-test/listVoices.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@

'use strict';

const path = require(`path`);
const test = require(`ava`);
const tools = require(`@google-cloud/nodejs-repo-tools`);
const path = require('path');
const assert = require('assert');
const tools = require('@google-cloud/nodejs-repo-tools');

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

test.before(tools.checkCredentials);
before(tools.checkCredentials);

test(`should list voices`, async t => {
it('should list voices', async () => {
const output = await tools.runAsync(`${cmd} list-voices`, cwd);
t.true(output.includes(`SSML Voice Gender: FEMALE`));
t.true(output.includes(`Natural Sample Rate Hertz: 24000`));
assert.ok(output.includes('SSML Voice Gender: FEMALE'));
assert.ok(output.includes('Natural Sample Rate Hertz: 24000'));
});
34 changes: 19 additions & 15 deletions texttospeech/system-test/quickstart.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,28 @@

'use strict';

const fs = require(`fs`);
const path = require(`path`);
const test = require(`ava`);
const tools = require(`@google-cloud/nodejs-repo-tools`);
const fs = require('fs');
const path = require('path');
const assert = require('assert');
const tools = require('@google-cloud/nodejs-repo-tools');

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

test.before(tools.stubConsole);
test.after.always(tools.restoreConsole);
test.after.always(async () => {
await fs.unlink(outputFile);
before(tools.stubConsole);
after(() => {
tools.restoreConsole();
try {
fs.unlinkSync(outputFile);
} catch(err) {
// Ignore error
}
});

test(`should synthesize speech to local mp3 file`, async t => {
t.false(fs.existsSync(outputFile));
it('should synthesize speech to local mp3 file', async () => {
assert.strictEqual(fs.existsSync(outputFile), false);
const output = await tools.runAsync(`${cmd}`, cwd);
t.true(output.includes(`Audio content written to file: output.mp3`));
t.true(fs.existsSync(outputFile));
assert.ok(output.includes('Audio content written to file: output.mp3'));
assert.ok(fs.existsSync(outputFile));
});
70 changes: 37 additions & 33 deletions texttospeech/system-test/synthesize.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,65 +17,69 @@

'use strict';

const fs = require(`fs`);
const path = require(`path`);
const test = require(`ava`);
const tools = require(`@google-cloud/nodejs-repo-tools`);
const fs = require('fs');
const path = require('path');
const assert = require('assert');
const tools = require('@google-cloud/nodejs-repo-tools');

const cmd = `node synthesize.js`;
const cwd = path.join(__dirname, `..`);
const text = `Hello there.`;
const ssml = `<speak>Hello there.</speak>`;
const outputFile = `test-output.mp3`;
const files = [`hello.txt`, `hello.ssml`].map(name => {
const cmd = 'node synthesize.js';
const cwd = path.join(__dirname, '..');
const text = 'Hello there.';
const ssml = '<speak>Hello there.</speak>';
const outputFile = 'test-output.mp3';
const files = ['hello.txt', 'hello.ssml'].map(name => {
return {
name,
localPath: path.resolve(path.join(__dirname, `../resources/${name}`)),
};
});

test.before(tools.checkCredentials);
before(tools.checkCredentials);

test.after.always(async () => {
await fs.unlink(outputFile);
afterEach(() => {
try {
fs.unlinkSync(outputFile);
} catch(err) {
// Ignore error
}
});

test(`should synthesize audio from text`, async t => {
t.false(fs.existsSync(outputFile));
it('should synthesize audio from text', async () => {
assert.strictEqual(fs.existsSync(outputFile), false);
const output = await tools.runAsync(
`${cmd} text '${text}' --outputFile '${outputFile}'`,
`${cmd} text '${text}' --outputFile ${outputFile}`,
cwd
);
t.true(output.includes(`Audio content written to file: ${outputFile}`));
t.true(fs.existsSync(outputFile));
assert.ok(output.includes(`Audio content written to file: ${outputFile}`));
assert.ok(fs.existsSync(outputFile));
});

test(`should synthesize audio from ssml`, async t => {
t.false(fs.existsSync(outputFile));
it('should synthesize audio from ssml', async () => {
assert.strictEqual(fs.existsSync(outputFile), false);
const output = await tools.runAsync(
`${cmd} ssml '${ssml}' --outputFile '${outputFile}'`,
`${cmd} ssml "${ssml}" --outputFile ${outputFile}`,
cwd
);
t.true(output.includes(`Audio content written to file: ${outputFile}`));
t.true(fs.existsSync(outputFile));
assert.ok(output.includes(`Audio content written to file: ${outputFile}`));
assert.ok(fs.existsSync(outputFile));
});

test(`should synthesize audio from text file`, async t => {
t.false(fs.existsSync(outputFile));
it('should synthesize audio from text file', async () => {
assert.strictEqual(fs.existsSync(outputFile), false);
const output = await tools.runAsync(
`${cmd} text-file '${files[0].localPath}' --outputFile '${outputFile}'`,
`${cmd} text-file ${files[0].localPath} --outputFile ${outputFile}`,
cwd
);
t.true(output.includes(`Audio content written to file: ${outputFile}`));
t.true(fs.existsSync(outputFile));
assert.ok(output.includes(`Audio content written to file: ${outputFile}`));
assert.ok(fs.existsSync(outputFile));
});

test(`should synthesize audio from ssml file`, async t => {
t.false(fs.existsSync(outputFile));
it('should synthesize audio from ssml file', async () => {
assert.strictEqual(fs.existsSync(outputFile), false);
const output = await tools.runAsync(
`${cmd} ssml-file '${files[1].localPath}' --outputFile '${outputFile}'`,
`${cmd} ssml-file ${files[1].localPath} --outputFile ${outputFile}`,
cwd
);
t.true(output.includes(`Audio content written to file: ${outputFile}`));
t.true(fs.existsSync(outputFile));
assert.ok(output.includes(`Audio content written to file: ${outputFile}`));
assert.ok(fs.existsSync(outputFile));
});

0 comments on commit 36ae426

Please sign in to comment.