Skip to content

Commit b805fef

Browse files
nareshqlogicfhinkel
authored andcommitted
refactor(jobs): convert ava tests to mocha (GoogleCloudPlatform#1147)
1 parent 843c6cd commit b805fef

15 files changed

Lines changed: 104 additions & 98 deletions

jobs/v2/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212
"node": ">=8.0.0"
1313
},
1414
"scripts": {
15-
"test": "repo-tools test run --cmd ava -- -T 20s --verbose system-test/*.test.js"
15+
"test": "repo-tools test install --cmd=npm -- run system-test",
16+
"system-test": "mocha system-test/*.test.js --timeout=60000"
1617
},
1718
"dependencies": {
1819
"googleapis": "^37.0.0"
1920
},
2021
"devDependencies": {
2122
"@google-cloud/nodejs-repo-tools": "^3.0.0",
22-
"ava": "0.25.0"
23+
"mocha": "^5.2.0"
2324
}
2425
}

jobs/v2/system-test/quickstart.test.js

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

1616
'use strict';
1717

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

21-
test(`should list companies`, async t => {
22-
const output = await tools.runAsync(`node quickstart.js`);
23-
t.true(output.includes(`Request ID`));
21+
it('should list companies', async () => {
22+
const output = await tools.runAsync('node quickstart.js');
23+
assert.strictEqual(output.includes('Request ID'), true);
2424
});

jobs/v3/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"node": ">=8.0.0"
1313
},
1414
"scripts": {
15-
"test": "repo-tools test run --cmd ava -- -T 40s --verbose system-test/*.test.js"
15+
"test": "repo-tools test install --cmd=npm -- run system-test",
16+
"system-test": "mocha system-test/*.test.js --timeout=40000"
1617
},
1718
"dependencies": {
1819
"googleapis": "37.2.0",
@@ -22,6 +23,6 @@
2223
},
2324
"devDependencies": {
2425
"@google-cloud/nodejs-repo-tools": "^3.0.0",
25-
"ava": "0.25.0"
26+
"mocha": "^5.2.0"
2627
}
2728
}

jobs/v3/system-test/auto-complete-sample.test.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515

1616
'use strict';
1717

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

21-
test(`should auto complete job titles within given companyName`, async t => {
22-
const output = await tools.runAsync(`node auto-complete-sample.js`);
21+
it('should auto complete job titles within given companyName', async () => {
22+
const output = await tools.runAsync('node auto-complete-sample.js');
2323
const pattern =
24-
`.*completionResults.*"suggestion":"Google","type":"COMPANY_NAME"}.*\n` +
25-
`.*completionResults.*"suggestion":"Software Engineer","type":"JOB_TITLE".*\n` +
26-
`.*completionResults.*"suggestion":"Software Engineer","type":"JOB_TITLE".*\n`;
24+
'.*completionResults.*"suggestion":"Google","type":"COMPANY_NAME"}.*\n' +
25+
'.*completionResults.*"suggestion":"Software Engineer","type":"JOB_TITLE".*\n' +
26+
'.*completionResults.*"suggestion":"Software Engineer","type":"JOB_TITLE".*\n';
2727

28-
t.regex(output, new RegExp(pattern));
28+
assert.strictEqual(new RegExp(pattern).test(output), true);
2929
});

jobs/v3/system-test/basic-company-sample.test.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@
1515

1616
'use strict';
1717

18-
const test = require(`ava`);
19-
const tools = require(`@google-cloud/nodejs-repo-tools`);
20-
const runSample = `'require("./basic-company-sample").runSample()'`;
18+
const assert = require('assert');
19+
const tools = require('@google-cloud/nodejs-repo-tools');
20+
const runSample = `require('./basic-company-sample').runSample()`;
2121

22-
test(`Should create a company, get a company, update a company, update a company with field mask and delete a company`, async t => {
22+
it('Should create a company, get a company, update a company, update a company with field mask and delete a company', async () => {
2323
const output = await tools.runAsync(`node -e ${runSample}`);
2424
const pattern =
25-
`.*Company generated:.*\n` +
26-
`.*Company created:.*\n` +
27-
`.*Company existed:.*\n` +
28-
`.*Company updated:.*elgoog.*\n` +
29-
`.*Company updated:.*changedTitle.*\n` +
30-
`.*Company deleted.*`;
25+
'.*Company generated:.*\n' +
26+
'.*Company created:.*\n' +
27+
'.*Company existed:.*\n' +
28+
'.*Company updated:.*elgoog.*\n' +
29+
'.*Company updated:.*changedTitle.*\n' +
30+
'.*Company deleted.*';
3131

32-
t.regex(output, new RegExp(pattern));
32+
assert.strictEqual(new RegExp(pattern).test(output), true);
3333
});

jobs/v3/system-test/basic-job-sample.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515

1616
'use strict';
1717

18-
const test = require(`ava`);
18+
const assert = require(`assert`);
1919
const tools = require(`@google-cloud/nodejs-repo-tools`);
20-
const runSample = `'require("./basic-job-sample").runSample()'`;
20+
const runSample = `require('./basic-job-sample').runSample()`;
2121

22-
test(`Should create a job, get a job, update a job, update a job with field mask and delete a job`, async t => {
22+
it(`Should create a job, get a job, update a job, update a job with field mask, and delete a job`, async () => {
2323
const output = await tools.runAsync(`node -e ${runSample}`);
2424
const pattern =
2525
`.*Job generated:.*\n` +
@@ -29,5 +29,5 @@ test(`Should create a job, get a job, update a job, update a job with field mask
2929
`.*Job updated:.*changedJobTitle.*\n` +
3030
`.*Job deleted.*`;
3131

32-
t.regex(output, new RegExp(pattern));
32+
assert.strictEqual(new RegExp(pattern).test(output), true);
3333
});

jobs/v3/system-test/batchdelete-jobs-sample.test.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@
1515

1616
'use strict';
1717

18-
const test = require(`ava`);
19-
const tools = require(`@google-cloud/nodejs-repo-tools`);
20-
const runSample = `'require("./basic-job-sample").runSample()'`;
18+
const assert = require('assert');
19+
const tools = require('@google-cloud/nodejs-repo-tools');
20+
const runSample = `require('./batchdelete-jobs-sample')`;
2121

22-
test(`Should batchDelete jobs.`, async t => {
22+
it('Should batchDelete jobs.', async () => {
2323
const output = await tools.runAsync(`node -e ${runSample}`);
24-
const pattern = `.*Batch deleted.*\n` + `.*{}*`;
25-
26-
t.regex(output, new RegExp(pattern));
24+
const pattern = '.*Batch deleted.*';
25+
assert.strictEqual(new RegExp(pattern).test(output), true);
2726
});

jobs/v3/system-test/commute-search-sample.test.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,18 @@
1515

1616
'use strict';
1717

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

21-
test(`should do a commute search`, async t => {
22-
const output = await tools.runAsync(`node commute-search-sample.js`);
21+
it('should do a commute search', async () => {
22+
const output = await tools.runAsync('node commute-search-sample.js');
2323

24-
t.regex(output, new RegExp(`.*matchingJobs.*commuteInfo.*`));
25-
t.regex(output, new RegExp(`.*matchingJobs.*1600 Amphitheatre Pkwy.*`));
24+
assert.strictEqual(
25+
new RegExp('.*matchingJobs.*commuteInfo.*').test(output),
26+
true
27+
);
28+
assert.strictEqual(
29+
new RegExp('.*matchingJobs.*1600 Amphitheatre Pkwy.*').test(output),
30+
true
31+
);
2632
});

jobs/v3/system-test/custom-attribute-sample.test.js

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

1616
'use strict';
1717

18-
const test = require(`ava`);
19-
const tools = require(`@google-cloud/nodejs-repo-tools`);
20-
const runSample = `'require("./custom-attribute-sample").runSample()'`;
18+
const assert = require('assert');
19+
const tools = require('@google-cloud/nodejs-repo-tools');
20+
const runSample = `require('./custom-attribute-sample').runSample()`;
2121

22-
test(`should search job with custom attribute filter`, async t => {
22+
it('should search job with custom attribute filter', async () => {
2323
const output = await tools.runAsync(`node -e ${runSample}`);
2424
const pattern =
25-
`.*Job created:.*jobWithACustomAttribute.*\n` +
26-
`.*matchingJobs.*jobWithACustomAttribute.*\n` +
27-
`.*matchingJobs.*jobWithACustomAttribute.*\n` +
28-
`.*matchingJobs.*jobWithACustomAttribute*`;
29-
30-
t.regex(output, new RegExp(pattern));
25+
'.*Job created:.*jobWithACustomAttribute.*\n' +
26+
'.*matchingJobs.*jobWithACustomAttribute.*\n' +
27+
'.*matchingJobs.*jobWithACustomAttribute.*\n' +
28+
'.*matchingJobs.*jobWithACustomAttribute*';
29+
assert.strictEqual(new RegExp(pattern).test(output), true);
3130
});

jobs/v3/system-test/email-alert-search-sample.test.js

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

1616
'use strict';
1717

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

21-
test(`should search jobs for alerts`, async t => {
22-
const output = await tools.runAsync(`node email-alert-search-sample.js`);
23-
t.true(output.includes(`matchingJobs`));
21+
it('should search jobs for alerts', async () => {
22+
const output = await tools.runAsync('node email-alert-search-sample.js');
23+
assert.strictEqual(output.includes('matchingJobs'), true);
2424
});

0 commit comments

Comments
 (0)