Skip to content

Commit 4d64f0a

Browse files
nareshqlogicJustinBeckwith
authored andcommitted
refactor(samples): convert sample tests from ava to mocha (#146)
1 parent 092583b commit 4d64f0a

File tree

5 files changed

+77
-76
lines changed

5 files changed

+77
-76
lines changed

video-intelligence/.eslintrc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
---
2+
env:
3+
mocha: true
24
rules:
35
no-console: off

video-intelligence/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
"node": ">=8"
1414
},
1515
"scripts": {
16-
"cover": "nyc --reporter=lcov --cache ava -T 20s --verbose test/*.test.js ./system-test/*.test.js && nyc report",
17-
"test": "ava -T 10m --serial --verbose system-test/*.test.js"
16+
"test": "mocha system-test/*.test.js --timeout=600000"
1817
},
1918
"dependencies": {
2019
"@google-cloud/video-intelligence": "^1.5.0",
Lines changed: 43 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/**
22
* Copyright 2017, Google, Inc.
3-
* Licensed under the Apache License, Version 2.0 (the `License`);
3+
* Licensed under the Apache License, Version 2.0 (the 'License');
44
* you may not use this file except in compliance with the License.
55
* You may obtain a copy of the License at
66
*
77
* http://www.apache.org/licenses/LICENSE-2.0
88
*
99
* Unless required by applicable law or agreed to in writing, software
10-
* distributed under the License is distributed on an `AS IS` BASIS,
10+
* distributed under the License is distributed on an 'AS IS' BASIS,
1111
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
* See the License for the specific language governing permissions and
1313
* limitations under the License.
@@ -17,71 +17,68 @@
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 analyze.js`;
25-
const cwd = path.join(__dirname, `..`);
24+
const cmd = 'node analyze.js';
25+
const cwd = path.join(__dirname, '..');
2626

27-
const url = `gs://nodejs-docs-samples-video/quickstart.mp4`;
28-
const shortUrl = `gs://nodejs-docs-samples-video/quickstart_short.mp4`;
29-
const file = `resources/cat.mp4`;
27+
const url = 'gs://nodejs-docs-samples-video/quickstart.mp4';
28+
const shortUrl = 'gs://nodejs-docs-samples-video/quickstart_short.mp4';
29+
const file = 'resources/cat.mp4';
3030

3131
// analyze_labels_gcs (one scene)
32-
test.serial(`should analyze labels in a GCS file with one scene`, async t => {
32+
it('should analyze labels in a GCS file with one scene', async () => {
3333
const output = await tools.runAsync(`${cmd} labels-gcs ${shortUrl}`, cwd);
34-
t.regex(output, /Label shirt occurs at:/);
35-
t.regex(output, /Confidence: \d+\.\d+/);
34+
assert.strictEqual(new RegExp(/Label shirt occurs at:/).test(output), true);
35+
assert.strictEqual(new RegExp(/Confidence: \d+\.\d+/).test(output), true);
3636
});
3737

3838
// analyze_labels_gcs (multiple scenes)
39-
test.serial(
40-
`should analyze labels in a GCS file with multiple scenes`,
41-
async t => {
42-
const output = await tools.runAsync(`${cmd} labels-gcs ${url}`, cwd);
43-
t.regex(output, /Label shirt occurs at:/);
44-
t.regex(output, /Confidence: \d+\.\d+/);
45-
}
46-
);
39+
it('should analyze labels in a GCS file with multiple scenes', async () => {
40+
const output = await tools.runAsync(`${cmd} labels-gcs ${url}`, cwd);
41+
assert.strictEqual(new RegExp(/Label shirt occurs at:/).test(output), true);
42+
assert.strictEqual(new RegExp(/Confidence: \d+\.\d+/).test(output), true);
43+
});
4744

4845
// analyze_labels_local
49-
test.serial(`should analyze labels in a local file`, async t => {
46+
it('should analyze labels in a local file', async () => {
5047
const output = await tools.runAsync(`${cmd} labels-file ${file}`, cwd);
51-
t.regex(output, /Label whiskers occurs at:/);
52-
t.regex(output, /Confidence: \d+\.\d+/);
48+
assert.strictEqual(
49+
new RegExp(/Label whiskers occurs at:/).test(output),
50+
true
51+
);
52+
assert.strictEqual(new RegExp(/Confidence: \d+\.\d+/).test(output), true);
5353
});
5454

5555
// analyze_shots (multiple shots)
56-
test.serial(
57-
`should analyze shots in a GCS file with multiple shots`,
58-
async t => {
59-
const output = await tools.runAsync(`${cmd} shots ${url}`, cwd);
60-
t.regex(output, /Scene 0 occurs from:/);
61-
}
62-
);
56+
it('should analyze shots in a GCS file with multiple shots', async () => {
57+
const output = await tools.runAsync(`${cmd} shots ${url}`, cwd);
58+
assert.strictEqual(new RegExp(/Scene 0 occurs from:/).test(output), true);
59+
});
6360

6461
// analyze_shots (one shot)
65-
test.serial(`should analyze shots in a GCS file with one shot`, async t => {
62+
it('should analyze shots in a GCS file with one shot', async () => {
6663
const output = await tools.runAsync(`${cmd} shots ${shortUrl}`, cwd);
67-
t.regex(output, /The entire video is one shot./);
64+
assert.strictEqual(
65+
new RegExp(/The entire video is one shot./).test(output),
66+
true
67+
);
6868
});
6969

7070
// analyze_safe_search
71-
test.serial(`should analyze safe search results in a GCS file`, async t => {
71+
it('should analyze safe search results in a GCS file', async () => {
7272
const output = await tools.runAsync(`${cmd} safe-search ${url}`, cwd);
73-
t.regex(output, /Time: \d+\.\d+s/);
74-
t.regex(output, /Explicit annotation results:/);
73+
assert.strictEqual(new RegExp(/Time: \d+\.\d+s/).test(output), true);
74+
assert.strictEqual(
75+
new RegExp(/Explicit annotation results:/).test(output),
76+
true
77+
);
7578
});
7679

7780
// analyze_video_transcription
78-
test.serial(
79-
`should analyze video transcription results in a GCS file`,
80-
async t => {
81-
const output = await tools.runAsync(
82-
`${cmd} transcription ${shortUrl}`,
83-
cwd
84-
);
85-
t.regex(output, /over the pass/);
86-
}
87-
);
81+
it('should analyze video transcription results in a GCS file', async () => {
82+
const output = await tools.runAsync(`${cmd} transcription ${shortUrl}`, cwd);
83+
assert.strictEqual(new RegExp(/over the pass/).test(output), true);
84+
});
Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/**
22
* Copyright 2018, Google, LLC
3-
* Licensed under the Apache License, Version 2.0 (the `License`);
3+
* Licensed under the Apache License, Version 2.0 (the 'License');
44
* you may not use this file except in compliance with the License.
55
* You may obtain a copy of the License at
66
*
77
* http://www.apache.org/licenses/LICENSE-2.0
88
*
99
* Unless required by applicable law or agreed to in writing, software
10-
* distributed under the License is distributed on an `AS IS` BASIS,
10+
* distributed under the License is distributed on an 'AS IS' BASIS,
1111
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
* See the License for the specific language governing permissions and
1313
* limitations under the License.
@@ -17,37 +17,37 @@
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 analyze.v1p2beta1.js`;
25-
const cwd = path.join(__dirname, `..`);
24+
const cmd = 'node analyze.v1p2beta1.js';
25+
const cwd = path.join(__dirname, '..');
2626

27-
const shortUrl = `gs://nodejs-docs-samples/video/googlework_short.mp4`;
28-
const url = `gs://nodejs-docs-samples/video/cat.mp4`;
29-
const file1 = `resources/cat.mp4`;
30-
const file2 = `resources/googlework_short.mp4`;
27+
const shortUrl = 'gs://nodejs-docs-samples/video/googlework_short.mp4';
28+
const url = 'gs://nodejs-docs-samples/video/cat.mp4';
29+
const file1 = 'resources/cat.mp4';
30+
const file2 = 'resources/googlework_short.mp4';
3131
const possibleTexts = /Google|GOOGLE|SUR|OMAR|ROTO|Vice President|58oo9|LONDRES|PARIS|METRO|RUE|CARLO/;
3232

33-
test.serial(`should detect text in a GCS file`, async t => {
33+
it('should detect text in a GCS file', async () => {
3434
const output = await tools.runAsync(`${cmd} video-text-gcs ${shortUrl}`, cwd);
35-
t.regex(output, possibleTexts);
35+
assert.strictEqual(new RegExp(possibleTexts).test(output), true);
3636
});
3737

38-
test.serial(`should detect text in a local file`, async t => {
38+
it('should detect text in a local file', async () => {
3939
const output = await tools.runAsync(`${cmd} video-text ${file2}`, cwd);
40-
t.regex(output, possibleTexts);
40+
assert.strictEqual(new RegExp(possibleTexts).test(output), true);
4141
});
4242

43-
test.serial(`should track objects in a GCS file`, async t => {
43+
it('should track objects in a GCS file', async () => {
4444
const output = await tools.runAsync(`${cmd} track-objects-gcs ${url}`, cwd);
45-
t.regex(output, /cat/);
46-
t.regex(output, /Confidence: \d+\.\d+/);
45+
assert.strictEqual(new RegExp(/cat/).test(output), true);
46+
assert.strictEqual(new RegExp(/Confidence: \d+\.\d+/).test(output), true);
4747
});
4848

49-
test.serial(`should track objects in a local file`, async t => {
49+
it('should track objects in a local file', async () => {
5050
const output = await tools.runAsync(`${cmd} track-objects ${file1}`, cwd);
51-
t.regex(output, /cat/);
52-
t.regex(output, /Confidence: \d+\.\d+/);
51+
assert.strictEqual(new RegExp(/cat/).test(output), true);
52+
assert.strictEqual(new RegExp(/Confidence: \d+\.\d+/).test(output), true);
5353
});

video-intelligence/system-test/quickstart.test.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,17 @@
1515

1616
'use strict';
1717

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

22-
const cmd = `node quickstart.js`;
23-
const cwd = path.join(__dirname, `..`);
22+
const cmd = 'node quickstart.js';
23+
const cwd = path.join(__dirname, '..');
2424

25-
test(`should analyze a hardcoded video`, async t => {
25+
it('should analyze a hardcoded video', async () => {
2626
const output = await tools.runAsync(cmd, cwd);
27-
t.regex(output, /Label standing occurs at:/);
27+
assert.strictEqual(
28+
new RegExp(/Label standing occurs at:/).test(output),
29+
true
30+
);
2831
});

0 commit comments

Comments
 (0)