Skip to content

Commit 36ae426

Browse files
nareshqlogicJustinBeckwith
authored andcommitted
refactor(samples): convert sample tests from ava to mocha (#133)
1 parent 5cb93dd commit 36ae426

File tree

6 files changed

+113
-96
lines changed

6 files changed

+113
-96
lines changed

texttospeech/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"node": ">=8"
1010
},
1111
"scripts": {
12-
"test": "ava -T 1m --verbose system-test/*.test.js"
12+
"test": "mocha system-test/*.test.js --timeout=600000"
1313
},
1414
"dependencies": {
1515
"@google-cloud/text-to-speech": "^0.3.0",
@@ -18,7 +18,7 @@
1818
},
1919
"devDependencies": {
2020
"@google-cloud/nodejs-repo-tools": "^3.0.0",
21-
"ava": "^0.25.0"
21+
"mocha": "^5.2.0"
2222
},
2323
"optionalDependencies": {
2424
"canvas": "^2.0.0"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
env:
3+
mocha: true
4+

texttospeech/system-test/audioProfile.test.js

Lines changed: 42 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,64 +17,69 @@
1717

1818
'use strict';
1919

20-
const fs = require(`fs`);
21-
const path = require(`path`);
22-
const test = require(`ava`);
23-
const tools = require(`@google-cloud/nodejs-repo-tools`);
20+
const fs = require('fs');
21+
const path = require('path');
22+
const assert = require('assert');
23+
const tools = require('@google-cloud/nodejs-repo-tools');
2424

25-
const cmd = `node audioProfile.js`;
26-
const cwd = path.join(__dirname, `..`);
27-
const text = `Hello Everybody! This is an Audio Profile Optimized Sound Byte.`;
28-
const outputFile1 = `phonetest.mp3`;
29-
const outputFile2 = `homeTheatreTest.mp3`;
30-
const outputFile3 = `carAudioTest.mp3`;
31-
const outputFile4 = `watchAudioTest.mp3`;
25+
const cmd = 'node audioProfile.js';
26+
const cwd = path.join(__dirname, '..');
27+
const text = 'Hello Everybody! This is an Audio Profile Optimized Sound Byte.';
28+
const outputFile1 = 'phonetest.mp3';
29+
const outputFile2 = 'homeTheatreTest.mp3';
30+
const outputFile3 = 'carAudioTest.mp3';
31+
const outputFile4 = 'watchAudioTest.mp3';
3232

33-
test.before(tools.checkCredentials);
33+
before(tools.checkCredentials);
3434

35-
test.after(async () => {
36-
await fs.unlink(outputFile1);
37-
await fs.unlink(outputFile2);
38-
await fs.unlink(outputFile3);
39-
await fs.unlink(outputFile4);
35+
after(() => {
36+
function unlink(outputFile) {
37+
try {
38+
fs.unlinkSync(outputFile);
39+
} catch(err) {
40+
// Ignore error
41+
}
42+
}
43+
44+
[outputFile1, outputFile2, outputFile3, outputFile4].map(unlink);
4045
});
4146

42-
test(`Should synthesize Speech for Telephone Audio Profile`, async t => {
43-
t.false(fs.existsSync(outputFile1));
47+
it('Should synthesize Speech for Telephone Audio Profile', async () => {
48+
assert.strictEqual(fs.existsSync(outputFile1), false);
4449
const output = await tools.runAsync(
45-
`${cmd} synthesize '${text}' -f '${outputFile1}' -e telephony-class-application`,
50+
`${cmd} synthesize '${text}' -f ${outputFile1} -e telephony-class-application`,
4651
cwd
4752
);
48-
t.true(output.includes(`Audio content written to file: ${outputFile1}`));
49-
t.true(fs.existsSync(outputFile1));
53+
assert.ok(output.includes(`Audio content written to file: ${outputFile1}`));
54+
assert.ok(fs.existsSync(outputFile1));
5055
});
5156

52-
test(`Should synthesize Speech for Home Theatre Audio Profile`, async t => {
53-
t.false(fs.existsSync(outputFile2));
57+
it('Should synthesize Speech for Home Theatre Audio Profile', async () => {
58+
assert.strictEqual(fs.existsSync(outputFile2), false);
5459
const output = await tools.runAsync(
55-
`${cmd} synthesize '${text}' -f '${outputFile2}' -e large-home-entertainment-class-device`,
60+
`${cmd} synthesize '${text}' -f ${outputFile2} -e large-home-entertainment-class-device`,
5661
cwd
5762
);
58-
t.true(output.includes(`Audio content written to file: ${outputFile2}`));
59-
t.true(fs.existsSync(outputFile2));
63+
assert.ok(output.includes(`Audio content written to file: ${outputFile2}`));
64+
assert.ok(fs.existsSync(outputFile2));
6065
});
6166

62-
test(`Should synthesize Speech for Car Audio Audio Profile`, async t => {
63-
t.false(fs.existsSync(outputFile3));
67+
it('Should synthesize Speech for Car Audio Audio Profile', async () => {
68+
assert.strictEqual(fs.existsSync(outputFile3), false);
6469
const output = await tools.runAsync(
65-
`${cmd} synthesize '${text}' -f '${outputFile3}' -e large-automotive-class-device`,
70+
`${cmd} synthesize '${text}' -f ${outputFile3} -e large-automotive-class-device`,
6671
cwd
6772
);
68-
t.true(output.includes(`Audio content written to file: ${outputFile3}`));
69-
t.true(fs.existsSync(outputFile3));
73+
assert.ok(output.includes(`Audio content written to file: ${outputFile3}`));
74+
assert.ok(fs.existsSync(outputFile3));
7075
});
7176

72-
test(`should synthesize Speech for Watch Audio Profile`, async t => {
73-
t.false(fs.existsSync(outputFile4));
77+
it('should synthesize Speech for Watch Audio Profile', async () => {
78+
assert.strictEqual(fs.existsSync(outputFile4), false);
7479
const output = await tools.runAsync(
75-
`${cmd} synthesize '${text}' -f '${outputFile4}' -e wearable-class-device`,
80+
`${cmd} synthesize '${text}' -f ${outputFile4} -e wearable-class-device`,
7681
cwd
7782
);
78-
t.true(output.includes(`Audio content written to file: ${outputFile4}`));
79-
t.true(fs.existsSync(outputFile4));
83+
assert.ok(output.includes(`Audio content written to file: ${outputFile4}`));
84+
assert.ok(fs.existsSync(outputFile4));
8085
});

texttospeech/system-test/listVoices.test.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@
1717

1818
'use strict';
1919

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

24-
const cmd = `node listVoices.js`;
25-
const cwd = path.join(__dirname, `..`);
24+
const cmd = 'node listVoices.js';
25+
const cwd = path.join(__dirname, '..');
2626

27-
test.before(tools.checkCredentials);
27+
before(tools.checkCredentials);
2828

29-
test(`should list voices`, async t => {
29+
it('should list voices', async () => {
3030
const output = await tools.runAsync(`${cmd} list-voices`, cwd);
31-
t.true(output.includes(`SSML Voice Gender: FEMALE`));
32-
t.true(output.includes(`Natural Sample Rate Hertz: 24000`));
31+
assert.ok(output.includes('SSML Voice Gender: FEMALE'));
32+
assert.ok(output.includes('Natural Sample Rate Hertz: 24000'));
3333
});

texttospeech/system-test/quickstart.test.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,28 @@
1717

1818
'use strict';
1919

20-
const fs = require(`fs`);
21-
const path = require(`path`);
22-
const test = require(`ava`);
23-
const tools = require(`@google-cloud/nodejs-repo-tools`);
20+
const fs = require('fs');
21+
const path = require('path');
22+
const assert = require('assert');
23+
const tools = require('@google-cloud/nodejs-repo-tools');
2424

25-
const outputFile = `output.mp3`;
26-
const cmd = `node quickstart.js`;
27-
const cwd = path.join(__dirname, `..`);
25+
const outputFile = 'output.mp3';
26+
const cmd = 'node quickstart.js';
27+
const cwd = path.join(__dirname, '..');
2828

29-
test.before(tools.stubConsole);
30-
test.after.always(tools.restoreConsole);
31-
test.after.always(async () => {
32-
await fs.unlink(outputFile);
29+
before(tools.stubConsole);
30+
after(() => {
31+
tools.restoreConsole();
32+
try {
33+
fs.unlinkSync(outputFile);
34+
} catch(err) {
35+
// Ignore error
36+
}
3337
});
3438

35-
test(`should synthesize speech to local mp3 file`, async t => {
36-
t.false(fs.existsSync(outputFile));
39+
it('should synthesize speech to local mp3 file', async () => {
40+
assert.strictEqual(fs.existsSync(outputFile), false);
3741
const output = await tools.runAsync(`${cmd}`, cwd);
38-
t.true(output.includes(`Audio content written to file: output.mp3`));
39-
t.true(fs.existsSync(outputFile));
42+
assert.ok(output.includes('Audio content written to file: output.mp3'));
43+
assert.ok(fs.existsSync(outputFile));
4044
});

texttospeech/system-test/synthesize.test.js

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,65 +17,69 @@
1717

1818
'use strict';
1919

20-
const fs = require(`fs`);
21-
const path = require(`path`);
22-
const test = require(`ava`);
23-
const tools = require(`@google-cloud/nodejs-repo-tools`);
20+
const fs = require('fs');
21+
const path = require('path');
22+
const assert = require('assert');
23+
const tools = require('@google-cloud/nodejs-repo-tools');
2424

25-
const cmd = `node synthesize.js`;
26-
const cwd = path.join(__dirname, `..`);
27-
const text = `Hello there.`;
28-
const ssml = `<speak>Hello there.</speak>`;
29-
const outputFile = `test-output.mp3`;
30-
const files = [`hello.txt`, `hello.ssml`].map(name => {
25+
const cmd = 'node synthesize.js';
26+
const cwd = path.join(__dirname, '..');
27+
const text = 'Hello there.';
28+
const ssml = '<speak>Hello there.</speak>';
29+
const outputFile = 'test-output.mp3';
30+
const files = ['hello.txt', 'hello.ssml'].map(name => {
3131
return {
3232
name,
3333
localPath: path.resolve(path.join(__dirname, `../resources/${name}`)),
3434
};
3535
});
3636

37-
test.before(tools.checkCredentials);
37+
before(tools.checkCredentials);
3838

39-
test.after.always(async () => {
40-
await fs.unlink(outputFile);
39+
afterEach(() => {
40+
try {
41+
fs.unlinkSync(outputFile);
42+
} catch(err) {
43+
// Ignore error
44+
}
4145
});
4246

43-
test(`should synthesize audio from text`, async t => {
44-
t.false(fs.existsSync(outputFile));
47+
it('should synthesize audio from text', async () => {
48+
assert.strictEqual(fs.existsSync(outputFile), false);
4549
const output = await tools.runAsync(
46-
`${cmd} text '${text}' --outputFile '${outputFile}'`,
50+
`${cmd} text '${text}' --outputFile ${outputFile}`,
4751
cwd
4852
);
49-
t.true(output.includes(`Audio content written to file: ${outputFile}`));
50-
t.true(fs.existsSync(outputFile));
53+
assert.ok(output.includes(`Audio content written to file: ${outputFile}`));
54+
assert.ok(fs.existsSync(outputFile));
5155
});
5256

53-
test(`should synthesize audio from ssml`, async t => {
54-
t.false(fs.existsSync(outputFile));
57+
it('should synthesize audio from ssml', async () => {
58+
assert.strictEqual(fs.existsSync(outputFile), false);
5559
const output = await tools.runAsync(
56-
`${cmd} ssml '${ssml}' --outputFile '${outputFile}'`,
60+
`${cmd} ssml "${ssml}" --outputFile ${outputFile}`,
5761
cwd
5862
);
59-
t.true(output.includes(`Audio content written to file: ${outputFile}`));
60-
t.true(fs.existsSync(outputFile));
63+
assert.ok(output.includes(`Audio content written to file: ${outputFile}`));
64+
assert.ok(fs.existsSync(outputFile));
6165
});
6266

63-
test(`should synthesize audio from text file`, async t => {
64-
t.false(fs.existsSync(outputFile));
67+
it('should synthesize audio from text file', async () => {
68+
assert.strictEqual(fs.existsSync(outputFile), false);
6569
const output = await tools.runAsync(
66-
`${cmd} text-file '${files[0].localPath}' --outputFile '${outputFile}'`,
70+
`${cmd} text-file ${files[0].localPath} --outputFile ${outputFile}`,
6771
cwd
6872
);
69-
t.true(output.includes(`Audio content written to file: ${outputFile}`));
70-
t.true(fs.existsSync(outputFile));
73+
assert.ok(output.includes(`Audio content written to file: ${outputFile}`));
74+
assert.ok(fs.existsSync(outputFile));
7175
});
7276

73-
test(`should synthesize audio from ssml file`, async t => {
74-
t.false(fs.existsSync(outputFile));
77+
it('should synthesize audio from ssml file', async () => {
78+
assert.strictEqual(fs.existsSync(outputFile), false);
7579
const output = await tools.runAsync(
76-
`${cmd} ssml-file '${files[1].localPath}' --outputFile '${outputFile}'`,
80+
`${cmd} ssml-file ${files[1].localPath} --outputFile ${outputFile}`,
7781
cwd
7882
);
79-
t.true(output.includes(`Audio content written to file: ${outputFile}`));
80-
t.true(fs.existsSync(outputFile));
83+
assert.ok(output.includes(`Audio content written to file: ${outputFile}`));
84+
assert.ok(fs.existsSync(outputFile));
8185
});

0 commit comments

Comments
 (0)