Skip to content

Commit 872a7c9

Browse files
Repo Migration (#6)
1 parent d693a7c commit 872a7c9

File tree

7 files changed

+154
-115
lines changed

7 files changed

+154
-115
lines changed

translate/.eslintrc.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
rules:
3+
no-console: off

translate/package.json

+8-25
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,23 @@
44
"private": true,
55
"license": "Apache-2.0",
66
"author": "Google Inc.",
7-
"repository": {
8-
"type": "git",
9-
"url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git"
10-
},
7+
"repository": "googleapis/nodejs-translate",
118
"engines": {
129
"node": ">=4.3.2"
1310
},
1411
"scripts": {
15-
"lint": "samples lint",
16-
"pretest": "npm run lint",
17-
"test": "samples test run --cmd ava -- -T 20s --verbose system-test/*.test.js"
12+
"ava": "ava -T 20s --verbose test/*.test.js ./system-test/*.test.js",
13+
"cover": "nyc --reporter=lcov --cache ava -T 20s --verbose test/*.test.js ./system-test/*.test.js && nyc report",
14+
"test": "repo-tools test run --cmd npm -- run cover"
1815
},
1916
"dependencies": {
2017
"@google-cloud/translate": "1.0.0",
21-
"yargs": "8.0.2"
18+
"yargs": "10.0.3"
2219
},
2320
"devDependencies": {
24-
"@google-cloud/nodejs-repo-tools": "1.4.17",
25-
"ava": "0.21.0",
21+
"@google-cloud/nodejs-repo-tools": "2.0.11",
22+
"ava": "0.22.0",
2623
"proxyquire": "1.8.0",
27-
"sinon": "3.2.0"
28-
},
29-
"cloud-repo-tools": {
30-
"requiresKeyFile": true,
31-
"requiresProjectId": true,
32-
"product": "translate",
33-
"samples": [
34-
{
35-
"id": "translate",
36-
"name": "Translate",
37-
"file": "translate.js",
38-
"docs_link": "https://cloud.google.com/translate/docs",
39-
"usage": "node translate.js --help"
40-
}
41-
]
24+
"sinon": "4.0.1"
4225
}
4326
}

translate/quickstart.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ const Translate = require('@google-cloud/translate');
2323
const projectId = 'YOUR_PROJECT_ID';
2424

2525
// Instantiates a client
26-
const translateClient = Translate({
27-
projectId: projectId
26+
const translate = new Translate({
27+
projectId: projectId,
2828
});
2929

3030
// The text to translate
@@ -33,14 +33,15 @@ const text = 'Hello, world!';
3333
const target = 'ru';
3434

3535
// Translates some text into Russian
36-
translateClient.translate(text, target)
37-
.then((results) => {
36+
translate
37+
.translate(text, target)
38+
.then(results => {
3839
const translation = results[0];
3940

4041
console.log(`Text: ${text}`);
4142
console.log(`Translation: ${translation}`);
4243
})
43-
.catch((err) => {
44+
.catch(err => {
4445
console.error('ERROR:', err);
4546
});
4647
// [END translate_quickstart]

translate/system-test/.eslintrc.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
rules:
3+
node/no-unpublished-require: off
4+
node/no-unsupported-features: off
5+
no-empty: off

translate/system-test/quickstart.test.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ test.before(tools.checkCredentials);
2525
test.before(tools.stubConsole);
2626
test.after.always(tools.restoreConsole);
2727

28-
test.cb(`should translate a string`, (t) => {
28+
test.cb(`should translate a string`, t => {
2929
const string = `Hello, world!`;
3030
const expectedTranslation = `Привет мир!`;
3131
const targetLanguage = `ru`;
@@ -34,15 +34,18 @@ test.cb(`should translate a string`, (t) => {
3434
t.is(_string, string);
3535
t.is(_targetLanguage, targetLanguage);
3636

37-
return translate.translate(_string, _targetLanguage)
37+
return translate
38+
.translate(_string, _targetLanguage)
3839
.then(([translation]) => {
3940
t.is(translation, expectedTranslation);
4041

4142
setTimeout(() => {
4243
try {
4344
t.is(console.log.callCount, 2);
4445
t.deepEqual(console.log.getCall(0).args, [`Text: ${string}`]);
45-
t.deepEqual(console.log.getCall(1).args, [`Translation: ${expectedTranslation}`]);
46+
t.deepEqual(console.log.getCall(1).args, [
47+
`Translation: ${expectedTranslation}`,
48+
]);
4649
t.end();
4750
} catch (err) {
4851
t.end(err);
@@ -51,10 +54,10 @@ test.cb(`should translate a string`, (t) => {
5154

5255
return [translation];
5356
});
54-
}
57+
},
5558
};
5659

5760
proxyquire(`../quickstart`, {
58-
'@google-cloud/translate': sinon.stub().returns(translateMock)
61+
'@google-cloud/translate': sinon.stub().returns(translateMock),
5962
});
6063
});

translate/system-test/translate.test.js

+30-14
Original file line numberDiff line numberDiff line change
@@ -29,55 +29,71 @@ const toLang = `ru`;
2929

3030
test.before(tools.checkCredentials);
3131

32-
test(`should detect language of a single string`, async (t) => {
32+
test(`should detect language of a single string`, async t => {
3333
const output = await tools.runAsync(`${cmd} detect "${text}"`, cwd);
3434
const [detection] = await translate.detect(text);
3535
const expected = `Detections:\n${text} => ${detection.language}`;
3636
t.is(output, expected);
3737
});
3838

39-
test(`should detect language of multiple strings`, async (t) => {
40-
const output = await tools.runAsync(`${cmd} detect "${text}" "${text2}"`, cwd);
39+
test(`should detect language of multiple strings`, async t => {
40+
const output = await tools.runAsync(
41+
`${cmd} detect "${text}" "${text2}"`,
42+
cwd
43+
);
4144
const [detections] = await translate.detect([text, text2]);
42-
const expected = `Detections:\n${text} => ${detections[0].language}\n${text2} => ${detections[1].language}`;
45+
const expected = `Detections:\n${text} => ${detections[0]
46+
.language}\n${text2} => ${detections[1].language}`;
4347
t.is(output, expected);
4448
});
4549

46-
test(`should list languages`, async (t) => {
50+
test(`should list languages`, async t => {
4751
const output = await tools.runAsync(`${cmd} list`, cwd);
4852
t.true(output.includes(`Languages:`));
4953
t.true(output.includes(`{ code: 'af', name: 'Afrikaans' }`));
5054
});
5155

52-
test(`should list languages with a target`, async (t) => {
56+
test(`should list languages with a target`, async t => {
5357
const output = await tools.runAsync(`${cmd} list es`, cwd);
5458
t.true(output.includes(`Languages:`));
5559
t.true(output.includes(`{ code: 'af', name: 'afrikáans' }`));
5660
});
5761

58-
test(`should translate a single string`, async (t) => {
59-
const output = await tools.runAsync(`${cmd} translate ${toLang} "${text}"`, cwd);
62+
test(`should translate a single string`, async t => {
63+
const output = await tools.runAsync(
64+
`${cmd} translate ${toLang} "${text}"`,
65+
cwd
66+
);
6067
const [translation] = await translate.translate(text, toLang);
6168
const expected = `Translations:\n${text} => (${toLang}) ${translation}`;
6269
t.is(output, expected);
6370
});
6471

65-
test(`should translate multiple strings`, async (t) => {
66-
const output = await tools.runAsync(`${cmd} translate ${toLang} "${text}" "${text2}"`, cwd);
72+
test(`should translate multiple strings`, async t => {
73+
const output = await tools.runAsync(
74+
`${cmd} translate ${toLang} "${text}" "${text2}"`,
75+
cwd
76+
);
6777
const [translations] = await translate.translate([text, text2], toLang);
6878
const expected = `Translations:\n${text} => (${toLang}) ${translations[0]}\n${text2} => (${toLang}) ${translations[1]}`;
6979
t.is(output, expected);
7080
});
7181

72-
test(`should translate a single string with a model`, async (t) => {
73-
const output = await tools.runAsync(`${cmd} translate-with-model ${toLang} ${model} "${text}"`, cwd);
82+
test(`should translate a single string with a model`, async t => {
83+
const output = await tools.runAsync(
84+
`${cmd} translate-with-model ${toLang} ${model} "${text}"`,
85+
cwd
86+
);
7487
const [translation] = await translate.translate(text, toLang);
7588
const expected = `Translations:\n${text} => (${toLang}) ${translation}`;
7689
t.is(output, expected);
7790
});
7891

79-
test(`should translate multiple strings with a model`, async (t) => {
80-
const output = await tools.runAsync(`${cmd} translate-with-model ${toLang} ${model} "${text}" "${text2}"`, cwd);
92+
test(`should translate multiple strings with a model`, async t => {
93+
const output = await tools.runAsync(
94+
`${cmd} translate-with-model ${toLang} ${model} "${text}" "${text2}"`,
95+
cwd
96+
);
8197
const [translations] = await translate.translate([text, text2], toLang);
8298
const expected = `Translations:\n${text} => (${toLang}) ${translations[0]}\n${text2} => (${toLang}) ${translations[1]}`;
8399
t.is(output, expected);

0 commit comments

Comments
 (0)