Skip to content

Commit 9a0ca02

Browse files
nareshqlogicJustinBeckwith
authored andcommitted
refactor(samples): convert sample tests from ava to mocha (#222)
1 parent a4cbac6 commit 9a0ca02

File tree

6 files changed

+283
-246
lines changed

6 files changed

+283
-246
lines changed

dialogflow/package.json

+6-3
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@
55
"license": "Apache-2.0",
66
"author": "Google LLC",
77
"repository": "googleapis/nodejs-dialogflow",
8-
"files": [ "*.js", "resources" ],
8+
"files": [
9+
"*.js",
10+
"resources"
11+
],
912
"engines": {
1013
"node": ">=8.0.0"
1114
},
1215
"scripts": {
13-
"test": "ava system-test"
16+
"test": "mocha system-test/*.test.js --timeout=600000"
1417
},
1518
"dependencies": {
1619
"dialogflow": "^0.7.0",
@@ -22,6 +25,6 @@
2225
},
2326
"devDependencies": {
2427
"@google-cloud/nodejs-repo-tools": "^3.0.0",
25-
"ava": "^0.25.0"
28+
"mocha": "^5.2.0"
2629
}
2730
}

dialogflow/system-test/.eslintrc.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
env:
3+
mocha: true

dialogflow/system-test/detect_test.js renamed to dialogflow/system-test/detect.test.js

+17-14
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,37 @@
1616
'use strict';
1717

1818
const path = require('path');
19-
const test = require('ava');
19+
const assert = require('assert');
2020
const {runAsync} = require('@google-cloud/nodejs-repo-tools');
2121

2222
const cmd = 'node detect.js';
23+
const cwd = path.join(__dirname, '..');
2324
const audioFilepathBookARoom = path
24-
.join(__dirname, `../resources/book_a_room.wav`)
25+
.join(__dirname, '../resources/book_a_room.wav')
2526
.replace(/(\s+)/g, '\\$1');
2627

27-
test('Should detect text queries', async t => {
28-
const output = await runAsync(`${cmd} text -q "hello"`);
29-
t.true(output.includes('Detected intent'));
28+
it('Should detect text queries', async () => {
29+
const output = await runAsync(`${cmd} text -q "hello"`, cwd);
30+
assert.strictEqual(output.includes('Detected intent'), true);
3031
});
3132

32-
test('Should detect event query', async t => {
33-
const output = await runAsync(`${cmd} event WELCOME`);
34-
t.true(output.includes('Query: WELCOME'));
33+
it('Should detect event query', async () => {
34+
const output = await runAsync(`${cmd} event WELCOME`, cwd);
35+
assert.strictEqual(output.includes('Query: WELCOME'), true);
3536
});
3637

37-
test('Should detect audio query', async t => {
38+
it('Should detect audio query', async () => {
3839
const output = await runAsync(
39-
`${cmd} audio ${audioFilepathBookARoom} -r 16000`
40+
`${cmd} audio ${audioFilepathBookARoom} -r 16000`,
41+
cwd
4042
);
41-
t.true(output.includes('Detected intent'));
43+
assert.strictEqual(output.includes('Detected intent'), true);
4244
});
4345

44-
test('Should detect audio query in streaming fashion', async t => {
46+
it('Should detect audio query in streaming fashion', async () => {
4547
const output = await runAsync(
46-
`${cmd} stream ${audioFilepathBookARoom} -r 16000`
48+
`${cmd} stream ${audioFilepathBookARoom} -r 16000`,
49+
cwd
4750
);
48-
t.true(output.includes('Detected intent'));
51+
assert.strictEqual(output.includes('Detected intent'), true);
4952
});

dialogflow/system-test/detect.v2beta1.test.js

+63-44
Original file line numberDiff line numberDiff line change
@@ -15,101 +15,120 @@
1515

1616
'use strict';
1717

18-
const test = require(`ava`);
18+
const path = require('path');
19+
const assert = require('assert');
1920
const {runAsync} = require('@google-cloud/nodejs-repo-tools');
2021
const uuid = require('uuid/v4');
2122

2223
const cmd = 'node detect.v2beta1.js';
23-
const testQuery = `Where is my data stored?`;
24+
const cwd = path.join(__dirname, '..');
25+
const testQuery = 'Where is my data stored?';
2426
const testKnowledgeBaseName = `${uuid().split('-')[0]}-TestKnowledgeBase`;
25-
const testDocName = `TestDoc`;
26-
const testDocumentPath = `https://cloud.google.com/storage/docs/faq`;
27+
const testDocName = 'TestDoc';
28+
const testDocumentPath = 'https://cloud.google.com/storage/docs/faq';
2729

28-
test.serial(`It should create a knowledge base`, async t => {
30+
it('It should create a knowledge base', async () => {
2931
// Check that the knowledge base does not yet exist
30-
let output = await runAsync(`${cmd} listKnowledgeBases`);
31-
t.false(output.includes(testKnowledgeBaseName));
32+
let output = await runAsync(`${cmd} listKnowledgeBases`, cwd);
33+
assert.strictEqual(output.includes(testKnowledgeBaseName), false);
3234

3335
// Creates a knowledge base
3436
output = await runAsync(
35-
`${cmd} createKnowledgeBase -k ${testKnowledgeBaseName}`
37+
`${cmd} createKnowledgeBase -k ${testKnowledgeBaseName}`,
38+
cwd
39+
);
40+
assert.strictEqual(
41+
output.includes(`displayName: ${testKnowledgeBaseName}`),
42+
true
3643
);
37-
t.true(output.includes(`displayName: ${testKnowledgeBaseName}`));
3844
const knowbaseFullName = output
39-
.split(`\n`)[0]
40-
.split(`:`)[1]
45+
.split('\n')[0]
46+
.split(':')[1]
4147
.trim();
4248
const knowbaseId = output
43-
.split(`\n`)[0]
44-
.split(`knowledgeBases/`)[1]
49+
.split('\n')[0]
50+
.split('knowledgeBases/')[1]
4551
.trim();
4652

4753
// List the knowledge base
48-
output = await runAsync(`${cmd} listKnowledgeBases`);
49-
t.true(output.includes(testKnowledgeBaseName));
54+
output = await runAsync(`${cmd} listKnowledgeBases`, cwd);
55+
assert.strictEqual(output.includes(testKnowledgeBaseName), true);
5056

5157
// Get the knowledge base
52-
output = await runAsync(`${cmd} getKnowledgeBase -b "${knowbaseId}"`);
53-
t.true(output.includes(`displayName: ${testKnowledgeBaseName}`));
54-
t.true(output.includes(`name: ${knowbaseFullName}`));
58+
output = await runAsync(`${cmd} getKnowledgeBase -b "${knowbaseId}"`, cwd);
59+
assert.strictEqual(
60+
output.includes(`displayName: ${testKnowledgeBaseName}`),
61+
true
62+
);
63+
assert.strictEqual(output.includes(`name: ${knowbaseFullName}`), true);
5564

5665
// Create a document
5766
output = await runAsync(
58-
`${cmd} createDocument -n "${knowbaseFullName}" -z "${testDocumentPath}" -m "${testDocName}"`
67+
`${cmd} createDocument -n "${knowbaseFullName}" -z "${testDocumentPath}" -m "${testDocName}"`,
68+
cwd
5969
);
60-
t.true(output.includes(`Document created`));
70+
assert.strictEqual(output.includes('Document created'), true);
6171

6272
// List the Document
6373
output = await runAsync(`${cmd} listDocuments -n "${knowbaseFullName}"`);
64-
const parsedOut = output.split(`\n`);
65-
const documentFullPath = parsedOut[parsedOut.length - 1].split(`:`)[1];
66-
t.true(output.includes(`There are 1 documents in ${knowbaseFullName}`));
74+
const parsedOut = output.split('\n');
75+
const documentFullPath = parsedOut[parsedOut.length - 1].split(':')[1];
76+
assert.strictEqual(
77+
output.includes(`There are 1 documents in ${knowbaseFullName}`),
78+
true
79+
);
6780

6881
// Detect intent with Knowledge Base
6982
output = await runAsync(
70-
`${cmd} detectIntentKnowledge -q "${testQuery}" -n "${knowbaseId}"`
83+
`${cmd} detectIntentKnowledge -q "${testQuery}" -n "${knowbaseId}"`,
84+
cwd
7185
);
72-
t.true(output.includes(`Detected Intent:`));
86+
assert.strictEqual(output.includes('Detected Intent:'), true);
7387

7488
// Delete the Document
75-
output = await runAsync(`${cmd} deleteDocument -d ${documentFullPath}`);
76-
t.true(output.includes(`document deleted`));
89+
output = await runAsync(`${cmd} deleteDocument -d ${documentFullPath}`, cwd);
90+
assert.strictEqual(output.includes('document deleted'), true);
7791

7892
// List the Document
79-
output = await runAsync(`${cmd} listDocuments -n "${knowbaseFullName}"`);
80-
t.false(output.includes(documentFullPath));
93+
output = await runAsync(`${cmd} listDocuments -n "${knowbaseFullName}"`, cwd);
94+
assert.strictEqual(output.includes(documentFullPath), false);
8195

8296
// Delete the Knowledge Base
8397
output = await runAsync(
84-
`${cmd} deleteKnowledgeBase -n "${knowbaseFullName}"`
98+
`${cmd} deleteKnowledgeBase -n "${knowbaseFullName}"`,
99+
cwd
85100
);
86101

87102
// List the Knowledge Base
88-
output = await runAsync(`${cmd} listKnowledgeBases`);
89-
t.false(output.includes(testKnowledgeBaseName));
103+
output = await runAsync(`${cmd} listKnowledgeBases`, cwd);
104+
assert.strictEqual(output.includes(testKnowledgeBaseName), false);
90105
});
91106

92-
test(`It should detect Intent with Model Selection`, async t => {
93-
const output = await runAsync(`${cmd} detectIntentwithModelSelection`);
94-
t.true(
107+
it('It should detect Intent with Model Selection', async () => {
108+
const output = await runAsync(`${cmd} detectIntentwithModelSelection`, cwd);
109+
assert.strictEqual(
95110
output.includes(
96-
`Response: I can help with that. Where would you like to reserve a room?`
97-
)
111+
'Response: I can help with that. Where would you like to reserve a room?'
112+
),
113+
true
98114
);
99115
});
100116

101-
test(`It should detect Intent with Text to Speech Response`, async t => {
117+
it('It should detect Intent with Text to Speech Response', async () => {
102118
const output = await runAsync(
103-
`${cmd} detectIntentwithTexttoSpeechResponse -q "${testQuery}"`
119+
`${cmd} detectIntentwithTexttoSpeechResponse -q "${testQuery}"`,
120+
cwd
104121
);
105-
t.true(
106-
output.includes(`Audio content written to file: ./resources/output.wav`)
122+
assert.strictEqual(
123+
output.includes('Audio content written to file: ./resources/output.wav'),
124+
true
107125
);
108126
});
109127

110-
test(`It should detect sentiment with intent`, async t => {
128+
it('It should detect sentiment with intent', async () => {
111129
const output = await runAsync(
112-
`${cmd} detectIntentandSentiment -q "${testQuery}"`
130+
`${cmd} detectIntentandSentiment -q "${testQuery}"`,
131+
cwd
113132
);
114-
t.true(output.includes(`Detected sentiment`));
133+
assert.strictEqual(output.includes('Detected sentiment'), true);
115134
});

0 commit comments

Comments
 (0)