Skip to content

Commit 054765b

Browse files
committed
Replaces Ava.js with the Mocha test framework.
Changes: * Updates local-test and system-test scripts in package.json. * Replaces ava with mocha devDependency in package.json. * Adds eslint-env hint to bypass 'is not defined' errors caused by the linter not recognizing definitions in Mocha. * Updates local and system tests to adhere to Mocha framework.
1 parent de51aba commit 054765b

3 files changed

Lines changed: 204 additions & 237 deletions

File tree

functions/speech-to-speech/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
],
2626
"scripts": {
2727
"lint": "repo-tools lint",
28-
"local-test": "ava -T 20s --verbose test/index.test.js",
29-
"system-test": "ava -T 20s --verbose test/sample.integration.http.test.js",
28+
"local-test": "mocha test/index.test.js",
29+
"system-test": "mocha --timeout 20000 test/sample.integration.http.test.js",
3030
"pretest": "npm run lint && sh test/updateFunctions.sh",
3131
"test": "npm run local-test && npm run system-test"
3232
},
@@ -40,7 +40,7 @@
4040
"devDependencies": {
4141
"@google-cloud/functions-emulator": "^1.0.0-beta.5",
4242
"@google-cloud/nodejs-repo-tools": "^2.3.5",
43-
"ava": "^0.25.0",
43+
"mocha": "^5.2.0",
4444
"semistandard": "^12.0.1",
4545
"supertest": "^3.3.0"
4646
},

functions/speech-to-speech/test/index.test.js

Lines changed: 105 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -13,150 +13,118 @@
1313
* limitations under the License.
1414
*/
1515

16-
const test = require('ava');
16+
/* eslint-env node, mocha */
17+
1718
const supertest = require('supertest');
1819
const request = supertest(process.env.BASE_URL);
1920

20-
test.cb('speechTranslate: No encoding field', t => {
21-
request
22-
.post('/speechTranslate')
23-
.send({
24-
// encoding: 'LINEAR16',
25-
sampleRateHertz: 16000,
26-
languageCode: 'en',
27-
audioContent: 'base64-audio-content'
28-
})
29-
.expect(400)
30-
.expect((response) => {
31-
t.is(response.text, 'Invalid encoding.');
32-
})
33-
.end(t.end);
34-
});
35-
36-
test.cb('speechTranslate: Empty encoding field', t => {
37-
request
38-
.post('/speechTranslate')
39-
.send({
40-
encoding: '',
41-
sampleRateHertz: 16000,
42-
languageCode: 'en',
43-
audioContent: 'base64-audio-content'
44-
})
45-
.expect(400)
46-
.expect((response) => {
47-
t.is(response.text, 'Invalid encoding.');
48-
})
49-
.end(t.end);
50-
});
51-
52-
test.cb('speechTranslate: No sampleRateHertz field', t => {
53-
request
54-
.post('/speechTranslate')
55-
.send({
56-
encoding: 'LINEAR16',
57-
// sampleRateHertz: 16000,
58-
languageCode: 'en',
59-
audioContent: 'base64-audio-content'
60-
})
61-
.expect(400)
62-
.expect((response) => {
63-
t.is(response.text, 'Sample rate hertz must be numeric.');
64-
})
65-
.end(t.end);
66-
});
67-
68-
test.cb('speechTranslate: Empty sampleRateHertz field', t => {
69-
request
70-
.post('/speechTranslate')
71-
.send({
72-
encoding: 'LINEAR16',
73-
sampleRateHertz: '',
74-
languageCode: 'en',
75-
audioContent: 'base64-audio-content'
76-
})
77-
.expect(400)
78-
.expect((response) => {
79-
t.is(response.text, 'Sample rate hertz must be numeric.');
80-
})
81-
.end(t.end);
82-
});
83-
84-
test.cb('speechTranslate: SampleRateHertz field is not a number', t => {
85-
request
86-
.post('/speechTranslate')
87-
.send({
88-
encoding: 'LINEAR16',
89-
sampleRateHertz: 'Not a number',
90-
languageCode: 'en',
91-
audioContent: 'base64-audio-content'
92-
})
93-
.expect(400)
94-
.expect((response) => {
95-
t.is(response.text, 'Sample rate hertz must be numeric.');
96-
})
97-
.end(t.end);
98-
});
99-
100-
test.cb('speechTranslate: No languageCode field', t => {
101-
request
102-
.post('/speechTranslate')
103-
.send({
104-
encoding: 'LINEAR16',
105-
sampleRateHertz: 16000,
106-
// languageCode: 'en',
107-
audioContent: 'base64-audio-content'
108-
})
109-
.expect(400)
110-
.expect((response) => {
111-
t.is(response.text, 'Invalid language code.');
112-
})
113-
.end(t.end);
21+
describe('Validate encoding field', function () {
22+
it('should fail if encoding field is missing.', function (done) {
23+
request
24+
.post('/speechTranslate')
25+
.send({
26+
// encoding: 'LINEAR16',
27+
sampleRateHertz: 16000,
28+
languageCode: 'en',
29+
audioContent: 'base64-audio-content'
30+
})
31+
.expect(400, 'Invalid encoding.', done);
32+
});
33+
it('should fail if encoding field is empty.', function (done) {
34+
request
35+
.post('/speechTranslate')
36+
.send({
37+
encoding: '',
38+
sampleRateHertz: 16000,
39+
languageCode: 'en',
40+
audioContent: 'base64-audio-content'
41+
})
42+
.expect(400, 'Invalid encoding.', done);
43+
});
11444
});
11545

116-
test.cb('speechTranslate: Empty languageCode field', t => {
117-
request
118-
.post('/speechTranslate')
119-
.send({
120-
encoding: 'LINEAR16',
121-
sampleRateHertz: 16000,
122-
languageCode: '',
123-
audioContent: 'base64-audio-content'
124-
})
125-
.expect(400)
126-
.expect((response) => {
127-
t.is(response.text, 'Invalid language code.');
128-
})
129-
.end(t.end);
46+
describe('Validate sampleRateHertz field', function () {
47+
it('should fail if sampleRateHertz field is missing.', function (done) {
48+
request
49+
.post('/speechTranslate')
50+
.send({
51+
encoding: 'LINEAR16',
52+
// sampleRateHertz: 16000,
53+
languageCode: 'en',
54+
audioContent: 'base64-audio-content'
55+
})
56+
.expect(400, 'Sample rate hertz must be numeric.', done);
57+
});
58+
it('should fail if sampleRateHertz field is empty.', function (done) {
59+
request
60+
.post('/speechTranslate')
61+
.send({
62+
encoding: 'LINEAR16',
63+
sampleRateHertz: '',
64+
languageCode: 'en',
65+
audioContent: 'base64-audio-content'
66+
})
67+
.expect(400, 'Sample rate hertz must be numeric.', done);
68+
});
69+
it('should fail if sampleRateHertz field is not numeric.', function (done) {
70+
request
71+
.post('/speechTranslate')
72+
.send({
73+
encoding: 'LINEAR16',
74+
sampleRateHertz: 'NaN',
75+
languageCode: 'en',
76+
audioContent: 'base64-audio-content'
77+
})
78+
.expect(400, 'Sample rate hertz must be numeric.', done);
79+
});
13080
});
13181

132-
test.cb('speechTranslate: No audioContent field', t => {
133-
request
134-
.post('/speechTranslate')
135-
.send({
136-
encoding: 'LINEAR16',
137-
sampleRateHertz: 16000,
138-
languageCode: 'en'
139-
// audioContent: 'base64-audio-content'
140-
})
141-
.expect(400)
142-
.expect((response) => {
143-
t.is(response.text, 'Invalid audio content.');
144-
})
145-
.end(t.end);
82+
describe('Validate languageCode field', function () {
83+
it('should fail if languageCode field is missing.', function (done) {
84+
request
85+
.post('/speechTranslate')
86+
.send({
87+
encoding: 'LINEAR16',
88+
sampleRateHertz: 16000,
89+
// languageCode: 'en',
90+
audioContent: 'base64-audio-content'
91+
})
92+
.expect(400, 'Invalid language code.', done);
93+
});
94+
it('should fail if languageCode field is empty.', function (done) {
95+
request
96+
.post('/speechTranslate')
97+
.send({
98+
encoding: 'LINEAR16',
99+
sampleRateHertz: 16000,
100+
languageCode: '',
101+
audioContent: 'base64-audio-content'
102+
})
103+
.expect(400, 'Invalid language code.', done);
104+
});
146105
});
147106

148-
test.cb('speechTranslate: Empty audioContent field', t => {
149-
request
150-
.post('/speechTranslate')
151-
.send({
152-
encoding: 'LINEAR16',
153-
sampleRateHertz: 16000,
154-
languageCode: 'en',
155-
audioContent: ''
156-
})
157-
.expect(400)
158-
.expect((response) => {
159-
t.is(response.text, 'Invalid audio content.');
160-
})
161-
.end(t.end);
107+
describe('Validate audioContent field', function () {
108+
it('should fail if audioContent field is missing.', function (done) {
109+
request
110+
.post('/speechTranslate')
111+
.send({
112+
encoding: 'LINEAR16',
113+
sampleRateHertz: 16000,
114+
languageCode: 'en'
115+
// audioContent: 'base64-audio-content'
116+
})
117+
.expect(400, 'Invalid audio content.', done);
118+
});
119+
it('should fail if audioContent field is empty.', function (done) {
120+
request
121+
.post('/speechTranslate')
122+
.send({
123+
encoding: 'LINEAR16',
124+
sampleRateHertz: 16000,
125+
languageCode: 'en',
126+
audioContent: ''
127+
})
128+
.expect(400, 'Invalid audio content.', done);
129+
});
162130
});

0 commit comments

Comments
 (0)