Skip to content

Commit f6bf465

Browse files
JustinBeckwithNimJay
authored andcommitted
Use mocha for sample tests (#119)
1 parent 45ef3bf commit f6bf465

File tree

7 files changed

+122
-123
lines changed

7 files changed

+122
-123
lines changed

cloud-language/snippets/package.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
"repository": "googleapis/nodejs-language",
99
"private": true,
1010
"scripts": {
11-
"ava": "ava -T 20s --verbose test/*.test.js ./system-test/*.test.js",
12-
"cover": "nyc --reporter=lcov --cache ava -T 20s --verbose test/*.test.js ./system-test/*.test.js && nyc report",
13-
"test": "npm run cover"
11+
"test": "mocha"
1412
},
1513
"dependencies": {
1614
"@google-cloud/language": "^1.2.0",
@@ -19,7 +17,7 @@
1917
},
2018
"devDependencies": {
2119
"@google-cloud/nodejs-repo-tools": "^2.3.0",
22-
"ava": "^0.25.0",
20+
"mocha": "^5.2.0",
2321
"uuid": "^3.2.1"
2422
}
2523
}

cloud-language/snippets/system-test/.eslintrc.yml

-5
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
env:
3+
mocha: true
4+
rules:
5+
node/no-unpublished-require: off

cloud-language/snippets/system-test/analyze.v1.test.js renamed to cloud-language/snippets/test/analyze.v1.test.js

+57-57
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const fs = require(`fs`);
1919
const path = require(`path`);
2020
const {Storage} = require(`@google-cloud/storage`);
2121
const storage = new Storage();
22-
const test = require(`ava`);
22+
const assert = require(`assert`);
2323
const tools = require(`@google-cloud/nodejs-repo-tools`);
2424
const uuid = require(`uuid`);
2525

@@ -33,119 +33,119 @@ const localFilePath2 = path.join(__dirname, `../resources/${fileName2}`);
3333
const text = fs.readFileSync(localFilePath, 'utf-8');
3434
const text2 = fs.readFileSync(localFilePath2, 'utf-8');
3535

36-
test.before(async () => {
36+
before(async () => {
3737
tools.checkCredentials();
3838
const [bucket] = await storage.createBucket(bucketName);
3939
await bucket.upload(localFilePath);
4040
await bucket.upload(localFilePath2);
4141
});
4242

43-
test.after.always(async () => {
43+
after(async () => {
4444
const bucket = storage.bucket(bucketName);
4545
await bucket.deleteFiles({force: true});
4646
await bucket.deleteFiles({force: true}); // Try a second time...
4747
await bucket.delete();
4848
});
4949

50-
test.beforeEach(tools.stubConsole);
51-
test.afterEach.always(tools.restoreConsole);
50+
beforeEach(async () => tools.stubConsole);
51+
afterEach(async () => tools.restoreConsole);
5252

53-
test(`should analyze sentiment in text`, async t => {
53+
it(`should analyze sentiment in text`, async () => {
5454
const output = await tools.runAsync(`${cmd} sentiment-text "${text}"`, cwd);
55-
t.regex(output, new RegExp(`Document sentiment:`));
56-
t.regex(output, new RegExp(`Sentence: ${text}`));
57-
t.regex(output, new RegExp(`Score: 0`));
58-
t.regex(output, new RegExp(`Magnitude: 0`));
55+
assert(RegExp(`Document sentiment:`).test(output));
56+
assert(RegExp(`Sentence: ${text}`).test(output));
57+
assert(RegExp(`Score: 0`).test(output));
58+
assert(RegExp(`Magnitude: 0`).test(output));
5959
});
6060

61-
test(`should analyze sentiment in a file`, async t => {
61+
it(`should analyze sentiment in a file`, async () => {
6262
const output = await tools.runAsync(
6363
`${cmd} sentiment-file ${bucketName} ${fileName}`,
6464
cwd
6565
);
66-
t.regex(output, new RegExp(`Document sentiment:`));
67-
t.regex(output, new RegExp(`Sentence: ${text}`));
68-
t.regex(output, new RegExp(`Score: 0`));
69-
t.regex(output, new RegExp(`Magnitude: 0`));
66+
assert(output, new RegExp(`Document sentiment:`).test(output));
67+
assert(RegExp(`Sentence: ${text}`).test(output));
68+
assert(RegExp(`Score: 0`).test(output));
69+
assert(RegExp(`Magnitude: 0`).test(output));
7070
});
7171

72-
test(`should analyze entities in text`, async t => {
72+
it(`should analyze entities in text`, async () => {
7373
const output = await tools.runAsync(`${cmd} entities-text "${text}"`, cwd);
74-
t.regex(output, new RegExp(`Obama`));
75-
t.regex(output, new RegExp(`Type: PERSON`));
76-
t.regex(output, new RegExp(`White House`));
77-
t.regex(output, new RegExp(`Type: LOCATION`));
74+
assert(RegExp(`Obama`).test(output));
75+
assert(RegExp(`Type: PERSON`).test(output));
76+
assert(RegExp(`White House`).test(output));
77+
assert(RegExp(`Type: LOCATION`).test(output));
7878
});
7979

80-
test('should analyze entities in a file', async t => {
80+
it('should analyze entities in a file', async () => {
8181
const output = await tools.runAsync(
8282
`${cmd} entities-file ${bucketName} ${fileName}`,
8383
cwd
8484
);
85-
t.regex(output, new RegExp(`Entities:`));
86-
t.regex(output, new RegExp(`Obama`));
87-
t.regex(output, new RegExp(`Type: PERSON`));
88-
t.regex(output, new RegExp(`White House`));
89-
t.regex(output, new RegExp(`Type: LOCATION`));
85+
assert(RegExp(`Entities:`).test(output));
86+
assert(RegExp(`Obama`).test(output));
87+
assert(RegExp(`Type: PERSON`).test(output));
88+
assert(RegExp(`White House`).test(output));
89+
assert(RegExp(`Type: LOCATION`).test(output));
9090
});
9191

92-
test(`should analyze syntax in text`, async t => {
92+
it(`should analyze syntax in text`, async () => {
9393
const output = await tools.runAsync(`${cmd} syntax-text "${text}"`, cwd);
94-
t.regex(output, new RegExp(`Tokens:`));
95-
t.regex(output, new RegExp(`NOUN:`));
96-
t.regex(output, new RegExp(`President`));
97-
t.regex(output, new RegExp(`Obama`));
98-
t.regex(output, new RegExp(`Morphology:`));
99-
t.regex(output, new RegExp(`tag: 'NOUN'`));
94+
assert(RegExp(`Tokens:`).test(output));
95+
assert(RegExp(`NOUN:`).test(output));
96+
assert(RegExp(`President`).test(output));
97+
assert(RegExp(`Obama`).test(output));
98+
assert(RegExp(`Morphology:`).test(output));
99+
assert(RegExp(`tag: 'NOUN'`).test(output));
100100
});
101101

102-
test('should analyze syntax in a file', async t => {
102+
it('should analyze syntax in a file', async () => {
103103
const output = await tools.runAsync(
104104
`${cmd} syntax-file ${bucketName} ${fileName}`,
105105
cwd
106106
);
107-
t.regex(output, new RegExp(`NOUN:`));
108-
t.regex(output, new RegExp(`President`));
109-
t.regex(output, new RegExp(`Obama`));
110-
t.regex(output, new RegExp(`Morphology:`));
111-
t.regex(output, new RegExp(`tag: 'NOUN'`));
107+
assert(RegExp(`NOUN:`).test(output));
108+
assert(RegExp(`President`).test(output));
109+
assert(RegExp(`Obama`).test(output));
110+
assert(RegExp(`Morphology:`).test(output));
111+
assert(RegExp(`tag: 'NOUN'`).test(output));
112112
});
113113

114-
test(`should analyze entity sentiment in text`, async t => {
114+
it(`should analyze entity sentiment in text`, async () => {
115115
const output = await tools.runAsync(
116116
`${cmd} entity-sentiment-text "${text}"`,
117117
cwd
118118
);
119-
t.regex(output, new RegExp(`Entities and sentiments:`));
120-
t.regex(output, new RegExp(`Obama`));
121-
t.regex(output, new RegExp(`PERSON`));
122-
t.regex(output, new RegExp(`Score: 0`));
123-
t.regex(output, new RegExp(`Magnitude: 0`));
119+
assert(RegExp(`Entities and sentiments:`).test(output));
120+
assert(RegExp(`Obama`).test(output));
121+
assert(RegExp(`PERSON`).test(output));
122+
assert(RegExp(`Score: 0`).test(output));
123+
assert(RegExp(`Magnitude: 0`).test(output));
124124
});
125125

126-
test('should analyze entity sentiment in a file', async t => {
126+
it('should analyze entity sentiment in a file', async () => {
127127
const output = await tools.runAsync(
128128
`${cmd} entity-sentiment-file ${bucketName} ${fileName}`,
129129
cwd
130130
);
131-
t.regex(output, new RegExp(`Entities and sentiments:`));
132-
t.regex(output, new RegExp(`Obama`));
133-
t.regex(output, new RegExp(`PERSON`));
134-
t.regex(output, new RegExp(`Score: 0`));
135-
t.regex(output, new RegExp(`Magnitude: 0`));
131+
assert(RegExp(`Entities and sentiments:`).test(output));
132+
assert(RegExp(`Obama`).test(output));
133+
assert(RegExp(`PERSON`).test(output));
134+
assert(RegExp(`Score: 0`).test(output));
135+
assert(RegExp(`Magnitude: 0`).test(output));
136136
});
137137

138-
test('should classify text in a file', async t => {
138+
it('should classify text in a file', async () => {
139139
const output = await tools.runAsync(
140140
`${cmd} classify-file ${bucketName} ${fileName2}`,
141141
cwd
142142
);
143-
t.regex(output, new RegExp(`Name:`));
144-
t.regex(output, new RegExp(`Computers & Electronics`));
143+
assert(RegExp(`Name:`).test(output));
144+
assert(RegExp(`Computers & Electronics`).test(output));
145145
});
146146

147-
test('should classify text in text', async t => {
147+
it('should classify text in text', async () => {
148148
const output = await tools.runAsync(`${cmd} classify-text "${text2}"`, cwd);
149-
t.regex(output, new RegExp(`Name:`));
150-
t.regex(output, new RegExp(`Computers & Electronics`));
149+
assert(RegExp(`Name:`).test(output));
150+
assert(RegExp(`Computers & Electronics`).test(output));
151151
});

cloud-language/snippets/system-test/analyze.v1beta2.test.js renamed to cloud-language/snippets/test/analyze.v1beta2.test.js

+49-49
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const fs = require(`fs`);
1919
const path = require(`path`);
2020
const {Storage} = require(`@google-cloud/storage`);
2121
const storage = new Storage();
22-
const test = require(`ava`);
22+
const assert = require('assert');
2323
const tools = require(`@google-cloud/nodejs-repo-tools`);
2424
const uuid = require(`uuid`);
2525

@@ -34,105 +34,105 @@ const text = fs.readFileSync(localFilePath, 'utf-8');
3434
const text2 = fs.readFileSync(localFilePath2, 'utf-8');
3535
const germanText = `Willkommen bei München`;
3636

37-
test.before(async () => {
37+
before(async () => {
3838
tools.checkCredentials();
3939
const [bucket] = await storage.createBucket(bucketName);
4040
await bucket.upload(localFilePath);
4141
await bucket.upload(localFilePath2);
4242
});
4343

44-
test.after.always(async () => {
44+
after(async () => {
4545
const bucket = storage.bucket(bucketName);
4646
await bucket.deleteFiles({force: true});
4747
await bucket.deleteFiles({force: true}); // Try a second time...
4848
await bucket.delete();
4949
});
5050

51-
test.beforeEach(tools.stubConsole);
52-
test.afterEach.always(tools.restoreConsole);
51+
beforeEach(async () => tools.stubConsole);
52+
afterEach(async () => tools.restoreConsole);
5353

54-
test(`should analyze sentiment in text`, async t => {
54+
it(`should analyze sentiment in text`, async () => {
5555
const output = await tools.runAsync(`${cmd} sentiment-text "${text}"`, cwd);
56-
t.regex(output, new RegExp(`Document sentiment:`));
57-
t.regex(output, new RegExp(`Sentence: ${text}`));
58-
t.regex(output, new RegExp(`Score: 0`));
59-
t.regex(output, new RegExp(`Magnitude: 0`));
56+
assert(RegExp(`Document sentiment:`).test(output));
57+
assert(RegExp(`Sentence: ${text}`).test(output));
58+
assert(RegExp(`Score: 0`).test(output));
59+
assert(RegExp(`Magnitude: 0`).test(output));
6060
});
6161

62-
test(`should analyze sentiment in a file`, async t => {
62+
it(`should analyze sentiment in a file`, async () => {
6363
const output = await tools.runAsync(
6464
`${cmd} sentiment-file ${bucketName} ${fileName}`,
6565
cwd
6666
);
67-
t.regex(output, new RegExp(`Document sentiment:`));
68-
t.regex(output, new RegExp(`Sentence: ${text}`));
69-
t.regex(output, new RegExp(`Score: 0`));
70-
t.regex(output, new RegExp(`Magnitude: 0`));
67+
assert(RegExp(`Document sentiment:`).test(output));
68+
assert(RegExp(`Sentence: ${text}`).test(output));
69+
assert(RegExp(`Score: 0`).test(output));
70+
assert(RegExp(`Magnitude: 0`).test(output));
7171
});
7272

73-
test(`should analyze entities in text`, async t => {
73+
it(`should analyze entities in text`, async () => {
7474
const output = await tools.runAsync(`${cmd} entities-text "${text}"`, cwd);
75-
t.regex(output, new RegExp(`Obama`));
76-
t.regex(output, new RegExp(`Type: PERSON`));
77-
t.regex(output, new RegExp(`White House`));
78-
t.regex(output, new RegExp(`Type: LOCATION`));
75+
assert(RegExp(`Obama`).test(output));
76+
assert(RegExp(`Type: PERSON`).test(output));
77+
assert(RegExp(`White House`).test(output));
78+
assert(RegExp(`Type: LOCATION`).test(output));
7979
});
8080

81-
test('should analyze entities in a file', async t => {
81+
it('should analyze entities in a file', async () => {
8282
const output = await tools.runAsync(
8383
`${cmd} entities-file ${bucketName} ${fileName}`,
8484
cwd
8585
);
86-
t.regex(output, new RegExp(`Entities:`));
87-
t.regex(output, new RegExp(`Type: PERSON`));
88-
t.regex(output, new RegExp(`White House`));
89-
t.regex(output, new RegExp(`Type: LOCATION`));
86+
assert(RegExp(`Entities:`).test(output));
87+
assert(RegExp(`Type: PERSON`).test(output));
88+
assert(RegExp(`White House`).test(output));
89+
assert(RegExp(`Type: LOCATION`).test(output));
9090
});
9191

92-
test(`should analyze syntax in text`, async t => {
92+
it(`should analyze syntax in text`, async () => {
9393
const output = await tools.runAsync(`${cmd} syntax-text "${text}"`, cwd);
94-
t.regex(output, new RegExp(`Parts of speech:`));
95-
t.regex(output, new RegExp(`NOUN:`));
96-
t.regex(output, new RegExp(`President`));
97-
t.regex(output, new RegExp(`Obama`));
98-
t.regex(output, new RegExp(`Morphology:`));
99-
t.regex(output, new RegExp(`tag: 'NOUN'`));
94+
assert(RegExp(`Parts of speech:`).test(output));
95+
assert(RegExp(`NOUN:`).test(output));
96+
assert(RegExp(`President`).test(output));
97+
assert(RegExp(`Obama`).test(output));
98+
assert(RegExp(`Morphology:`).test(output));
99+
assert(RegExp(`tag: 'NOUN'`).test(output));
100100
});
101101

102-
test('should analyze syntax in a file', async t => {
102+
it('should analyze syntax in a file', async () => {
103103
const output = await tools.runAsync(
104104
`${cmd} syntax-file ${bucketName} ${fileName}`,
105105
cwd
106106
);
107-
t.regex(output, new RegExp(`NOUN:`));
108-
t.regex(output, new RegExp(`President`));
109-
t.regex(output, new RegExp(`Obama`));
110-
t.regex(output, new RegExp(`Morphology:`));
111-
t.regex(output, new RegExp(`tag: 'NOUN'`));
107+
assert(RegExp(`NOUN:`).test(output));
108+
assert(RegExp(`President`).test(output));
109+
assert(RegExp(`Obama`).test(output));
110+
assert(RegExp(`Morphology:`).test(output));
111+
assert(RegExp(`tag: 'NOUN'`).test(output));
112112
});
113113

114-
test('should analyze syntax in a 1.1 language (German)', async t => {
114+
it('should analyze syntax in a 1.1 language (German)', async () => {
115115
const output = await tools.runAsync(
116116
`${cmd} syntax-text "${germanText}"`,
117117
cwd
118118
);
119-
t.regex(output, new RegExp(`Parts of speech:`));
120-
t.regex(output, new RegExp(`ADV: Willkommen`));
121-
t.regex(output, new RegExp(`ADP: bei`));
122-
t.regex(output, new RegExp(`NOUN: München`));
119+
assert(RegExp(`Parts of speech:`).test(output));
120+
assert(RegExp(`ADV: Willkommen`).test(output));
121+
assert(RegExp(`ADP: bei`).test(output));
122+
assert(RegExp(`NOUN: München`).test(output));
123123
});
124124

125-
test('should classify text in a file', async t => {
125+
it('should classify text in a file', async () => {
126126
const output = await tools.runAsync(
127127
`${cmd} classify-file ${bucketName} ${fileName2}`,
128128
cwd
129129
);
130-
t.regex(output, new RegExp(`Name:`));
131-
t.regex(output, new RegExp(`Computers & Electronics`));
130+
assert(RegExp(`Name:`).test(output));
131+
assert(RegExp(`Computers & Electronics`).test(output));
132132
});
133133

134-
test('should classify text in text', async t => {
134+
it('should classify text in text', async () => {
135135
const output = await tools.runAsync(`${cmd} classify-text "${text2}"`, cwd);
136-
t.regex(output, new RegExp(`Name:`));
137-
t.regex(output, new RegExp(`Computers & Electronics`));
136+
assert(RegExp(`Name:`).test(output));
137+
assert(RegExp(`Computers & Electronics`).test(output));
138138
});
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--timeout 20000
2+
--throw-deprecation

0 commit comments

Comments
 (0)