Skip to content

Commit 258d093

Browse files
JustinBeckwithsofisl
authored andcommitted
refactor: modernize the sample tests (#185)
* refactor: modernize the sample tests * lintalicious
1 parent e37ee9d commit 258d093

4 files changed

Lines changed: 16 additions & 19 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
---
22
rules:
33
no-console: off
4+
node/no-missing-require: off

packages/google-cloud-language/samples/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"resources"
1313
],
1414
"scripts": {
15-
"test": "mocha"
15+
"test": "mocha --timeout 60000"
1616
},
1717
"dependencies": {
1818
"@google-cloud/automl": "^0.1.1",
@@ -22,7 +22,8 @@
2222
"yargs": "^12.0.0"
2323
},
2424
"devDependencies": {
25-
"@google-cloud/nodejs-repo-tools": "^3.0.0",
25+
"chai": "^4.2.0",
26+
"execa": "^1.0.0",
2627
"mocha": "^5.2.0",
2728
"uuid": "^3.2.1"
2829
}

packages/google-cloud-language/samples/quickstart.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
'use strict';
1717

1818
// [START language_quickstart]
19-
async function main() {
19+
async function quickstart() {
2020
// Imports the Google Cloud client library
2121
const language = require('@google-cloud/language');
2222

@@ -39,6 +39,6 @@ async function main() {
3939
console.log(`Sentiment score: ${sentiment.score}`);
4040
console.log(`Sentiment magnitude: ${sentiment.magnitude}`);
4141
}
42-
43-
main().catch(console.error);
4442
// [END language_quickstart]
43+
44+
quickstart().catch(console.error);

packages/google-cloud-language/samples/test/quickstart.test.js

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

1616
'use strict';
1717

18-
const path = require(`path`);
19-
const assert = require('assert');
20-
const tools = require(`@google-cloud/nodejs-repo-tools`);
18+
const {assert} = require('chai');
19+
const execa = require('execa');
2120

22-
const cmd = `node quickstart.js`;
23-
const cwd = path.join(__dirname, `..`);
24-
25-
beforeEach(async () => tools.stubConsole);
26-
afterEach(async () => tools.restoreConsole);
27-
28-
it(`should analyze sentiment in text`, async () => {
29-
const output = await tools.runAsync(cmd, cwd);
30-
assert(RegExp('Text: Hello, world!').test(output));
31-
assert(RegExp('Sentiment score: ').test(output));
32-
assert(RegExp('Sentiment magnitude: ').test(output));
21+
describe('quickstart', () => {
22+
it('should analyze sentiment in text', async () => {
23+
const {stdout} = await execa.shell('node quickstart.js');
24+
assert(stdout, /Text: Hello, world!/);
25+
assert(stdout, /Sentiment score: /);
26+
assert(stdout, /Sentiment magnitude: /);
27+
});
3328
});

0 commit comments

Comments
 (0)