Skip to content

Commit

Permalink
Use mocha for sample tests (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith authored and sofisl committed Oct 13, 2022
1 parent ee20f1b commit e71d070
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
6 changes: 2 additions & 4 deletions packages/google-cloud-language/samples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
"repository": "googleapis/nodejs-language",
"private": true,
"scripts": {
"ava": "ava -T 20s --verbose test/*.test.js ./system-test/*.test.js",
"cover": "nyc --reporter=lcov --cache ava -T 20s --verbose test/*.test.js ./system-test/*.test.js && nyc report",
"test": "npm run cover"
"test": "mocha"
},
"dependencies": {
"@google-cloud/language": "^1.2.0",
Expand All @@ -19,7 +17,7 @@
},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "^2.3.0",
"ava": "^0.25.0",
"mocha": "^5.2.0",
"uuid": "^3.2.1"
}
}
33 changes: 33 additions & 0 deletions packages/google-cloud-language/samples/test/quickstart.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Copyright 2017, Google, Inc.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

const path = require(`path`);
const assert = require('assert');
const tools = require(`@google-cloud/nodejs-repo-tools`);

const cmd = `node quickstart.js`;
const cwd = path.join(__dirname, `..`);

beforeEach(async () => tools.stubConsole);
afterEach(async () => tools.restoreConsole);

it(`should analyze sentiment in text`, async () => {
const output = await tools.runAsync(cmd, cwd);
assert(RegExp('Text: Hello, world!').test(output));
assert(RegExp('Sentiment score: ').test(output));
assert(RegExp('Sentiment magnitude: ').test(output));
});

0 comments on commit e71d070

Please sign in to comment.