Skip to content

Commit 1a91f3d

Browse files
jmdobryAce Nassri
authored and
Ace Nassri
committed
Cleanup App Engine samples and re-work tests. (#354)
1 parent e9c0f92 commit 1a91f3d

File tree

10 files changed

+6033
-213
lines changed

10 files changed

+6033
-213
lines changed

cloud-language/snippets/analyze.js

+6-8
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function analyzeSentimentOfText (text) {
3333
document.detectSentiment()
3434
.then((results) => {
3535
const sentiment = results[1].documentSentiment;
36-
console.log(`Document sentiment:`)
36+
console.log(`Document sentiment:`);
3737
console.log(` Score: ${sentiment.score}`);
3838
console.log(` Magnitude: ${sentiment.magnitude}`);
3939

@@ -76,7 +76,7 @@ function analyzeSentimentInFile (bucketName, fileName) {
7676
document.detectSentiment()
7777
.then((results) => {
7878
const sentiment = results[1].documentSentiment;
79-
console.log(`Document sentiment:`)
79+
console.log(`Document sentiment:`);
8080
console.log(` Score: ${sentiment.score}`);
8181
console.log(` Magnitude: ${sentiment.magnitude}`);
8282

@@ -263,7 +263,7 @@ function analyzeEntitySentimentOfText (text) {
263263
.then((results) => {
264264
const entities = results[0].entities;
265265

266-
console.log(`Entities and sentiments:`)
266+
console.log(`Entities and sentiments:`);
267267
entities.forEach((entity) => {
268268
console.log(` Name: ${entity.name}`);
269269
console.log(` Type: ${entity.type}`);
@@ -279,13 +279,11 @@ function analyzeEntitySentimentOfText (text) {
279279

280280
function analyzeEntitySentimentInFile (bucketName, fileName) {
281281
// [START language_entity_sentiment_file]
282-
// Imports the Google Cloud client libraries
282+
// Imports the Google Cloud client library
283283
const Language = require('@google-cloud/language').v1beta2();
284-
const Storage = require('@google-cloud/storage');
285284

286285
// Instantiates the clients
287286
const language = Language.languageServiceClient();
288-
const storage = Storage();
289287

290288
// The name of the bucket where the file resides, e.g. "my-bucket"
291289
// const bucketName = 'my-bucket';
@@ -306,7 +304,7 @@ function analyzeEntitySentimentInFile (bucketName, fileName) {
306304
.then((results) => {
307305
const entities = results[0].entities;
308306

309-
console.log(`Entities and sentiments:`)
307+
console.log(`Entities and sentiments:`);
310308
entities.forEach((entity) => {
311309
console.log(` Name: ${entity.name}`);
312310
console.log(` Type: ${entity.type}`);
@@ -320,7 +318,7 @@ function analyzeEntitySentimentInFile (bucketName, fileName) {
320318
// [END language_entity_sentiment_file]
321319
}
322320

323-
require(`yargs`)
321+
require(`yargs`) // eslint-disable-line
324322
.demand(1)
325323
.command(
326324
`sentiment-text <text>`,

cloud-language/snippets/package.json

+21-4
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,34 @@
22
"name": "nodejs-docs-samples-language",
33
"version": "0.0.1",
44
"private": true,
5-
"license": "Apache Version 2.0",
5+
"license": "Apache-2.0",
66
"author": "Google Inc.",
7+
"repository": {
8+
"type": "git",
9+
"url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git"
10+
},
11+
"cloud": {
12+
"requiresKeyFile": true,
13+
"requiresProjectId": true
14+
},
15+
"engines": {
16+
"node": ">=4.3.2"
17+
},
718
"scripts": {
8-
"test": "cd ..; npm run st -- --verbose language/system-test/*.test.js"
19+
"lint": "samples lint \"*.js\" \"system-test/*.js\" \"slackbot/*.js\" \"slackbot/system-test/*.js\"",
20+
"pretest": "npm run lint",
21+
"system-test": "ava -T 20s --verbose system-test/*.test.js",
22+
"test": "npm run system-test"
923
},
1024
"dependencies": {
1125
"@google-cloud/language": "0.10.3",
1226
"@google-cloud/storage": "1.1.0",
1327
"yargs": "7.1.0"
1428
},
15-
"engines": {
16-
"node": ">=4.3.2"
29+
"devDependencies": {
30+
"@google-cloud/nodejs-repo-tools": "1.3.1",
31+
"ava": "0.19.1",
32+
"proxyquire": "1.7.11",
33+
"sinon": "2.1.0"
1734
}
1835
}

cloud-language/snippets/quickstart.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016, Google, Inc.
2+
* Copyright 2017, Google, Inc.
33
* 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
+24-7
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,37 @@
11
{
22
"name": "kubernetes-slack-botkit-example",
3+
"description": "A Slack Botkit bot, running on Kubernetes.",
34
"version": "0.0.1",
45
"private": true,
5-
"license": "Apache Version 2.0",
6+
"license": "Apache-2.0",
67
"author": "Google Inc.",
7-
"description": "A Slack Botkit bot, running on Kubernetes.",
8+
"repository": {
9+
"type": "git",
10+
"url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git"
11+
},
12+
"cloud": {
13+
"requiresKeyFile": true,
14+
"requiresProjectId": true
15+
},
816
"main": "demo_bot.js",
17+
"engines": {
18+
"node": ">=4.3.2"
19+
},
20+
"scripts": {
21+
"lint": "samples lint",
22+
"pretest": "npm run lint",
23+
"system-test": "ava -T 20s --verbose system-test/*.test.js",
24+
"test": "npm run system-test"
25+
},
926
"dependencies": {
1027
"botkit": "0.0.5",
1128
"@google-cloud/language": "0.10.2",
1229
"sqlite3": "3.1.8"
1330
},
14-
"scripts": {
15-
"test": "cd ../..; npm run st -- --verbose language/slackbot/system-test/*.test.js"
16-
},
17-
"engines": {
18-
"node": ">=4.3.2"
31+
"devDependencies": {
32+
"@google-cloud/nodejs-repo-tools": "1.3.1",
33+
"ava": "0.19.1",
34+
"proxyquire": "1.7.11",
35+
"sinon": "2.1.0"
1936
}
2037
}

cloud-language/snippets/slackbot/system-test/controller.test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016, Google, Inc.
2+
* Copyright 2017, Google, Inc.
33
* 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
@@ -15,11 +15,11 @@
1515

1616
'use strict';
1717

18-
require(`../../../system-test/_setup`);
19-
2018
const fs = require(`fs`);
2119
const path = require(`path`);
2220
const proxyquire = require(`proxyquire`).noCallThru();
21+
const sinon = require(`sinon`);
22+
const test = require(`ava`);
2323

2424
const SLACK_TOKEN_PATH = path.join(__dirname, `../.token`);
2525

cloud-language/snippets/slackbot/system-test/demo_bot.test.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016, Google, Inc.
2+
* Copyright 2017, Google, Inc.
33
* 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
@@ -15,19 +15,21 @@
1515

1616
'use strict';
1717

18-
require(`../../../system-test/_setup`);
19-
2018
const fs = require(`fs`);
2119
const path = require(`path`);
2220
const proxyquire = require(`proxyquire`).noCallThru();
21+
const sinon = require(`sinon`);
2322
const sqlite3 = require(`sqlite3`).verbose();
23+
const test = require(`ava`);
24+
const tools = require(`@google-cloud/nodejs-repo-tools`);
2425

2526
const DB_PATH = path.join(__dirname, `../slackDB.db`);
2627
const SLACK_TOKEN_PATH = path.join(__dirname, `../.token`);
2728
const text = `President Obama is speaking at the White House.`;
2829

2930
let db, controllerMock, botkitMock, botMock, program;
3031

32+
test.before(tools.checkCredentials);
3133
test.before.cb((t) => {
3234
fs.unlink(DB_PATH, (err) => {
3335
if (err && err.code !== `ENOENT`) {

0 commit comments

Comments
 (0)