1515
1616'use strict' ;
1717
18- const Translate = require ( `@google-cloud/translate` ) ;
18+ require ( `../../system-test/_setup` ) ;
19+
20+ const translate = require ( `@google-cloud/translate` ) ( ) ;
1921const path = require ( `path` ) ;
20- const run = require ( `../../utils` ) . run ;
2122
2223const cwd = path . join ( __dirname , `..` ) ;
2324const cmd = `node translate.js` ;
@@ -26,72 +27,56 @@ const text2 = `Goodbye!`;
2627const model = `nmt` ;
2728const toLang = `ru` ;
2829
29- describe ( `translate:translate` , ( ) => {
30- const translate = Translate ( ) ;
31-
32- it ( `should detect language of a single string` , ( ) => {
33- const output = run ( `${ cmd } detect "${ text } "` , cwd ) ;
34- return translate . detect ( text )
35- . then ( ( results ) => {
36- const expected = `Detections:\n${ text } => ${ results [ 0 ] . language } ` ;
37- assert . equal ( output , expected ) ;
38- } ) ;
39- } ) ;
30+ test ( `should detect language of a single string` , async ( t ) => {
31+ const output = await runAsync ( `${ cmd } detect "${ text } "` , cwd ) ;
32+ const [ detection ] = await translate . detect ( text ) ;
33+ const expected = `Detections:\n${ text } => ${ detection . language } ` ;
34+ t . is ( output , expected ) ;
35+ } ) ;
4036
41- it ( `should detect language of multiple strings` , ( ) => {
42- const output = run ( `${ cmd } detect "${ text } " "${ text2 } "` , cwd ) ;
43- return translate . detect ( [ text , text2 ] )
44- . then ( ( results ) => {
45- const expected = `Detections:\n${ text } => ${ results [ 0 ] [ 0 ] . language } \n${ text2 } => ${ results [ 0 ] [ 1 ] . language } ` ;
46- assert . equal ( output , expected ) ;
47- } ) ;
48- } ) ;
37+ test ( `should detect language of multiple strings` , async ( t ) => {
38+ const output = await runAsync ( `${ cmd } detect "${ text } " "${ text2 } "` , cwd ) ;
39+ const [ detections ] = await translate . detect ( [ text , text2 ] ) ;
40+ const expected = `Detections:\n${ text } => ${ detections [ 0 ] . language } \n${ text2 } => ${ detections [ 1 ] . language } ` ;
41+ t . is ( output , expected ) ;
42+ } ) ;
4943
50- it ( `should list languages` , ( ) => {
51- const output = run ( `${ cmd } list` , cwd ) ;
52- assert . equal ( output . includes ( `Languages:` ) , true ) ;
53- assert . equal ( output . includes ( `{ code: 'af', name: 'Afrikaans' }` ) , true ) ;
54- } ) ;
44+ test ( `should list languages` , async ( t ) => {
45+ const output = await runAsync ( `${ cmd } list` , cwd ) ;
46+ t . true ( output . includes ( `Languages:` ) ) ;
47+ t . true ( output . includes ( `{ code: 'af', name: 'Afrikaans' }` ) ) ;
48+ } ) ;
5549
56- it ( `should list languages with a target` , ( ) => {
57- const output = run ( `${ cmd } list es` , cwd ) ;
58- assert . equal ( output . includes ( `Languages:` ) , true ) ;
59- assert . equal ( output . includes ( `{ code: 'af', name: 'afrikáans' }` ) , true ) ;
60- } ) ;
50+ test ( `should list languages with a target` , async ( t ) => {
51+ const output = await runAsync ( `${ cmd } list es` , cwd ) ;
52+ t . true ( output . includes ( `Languages:` ) ) ;
53+ t . true ( output . includes ( `{ code: 'af', name: 'afrikáans' }` ) ) ;
54+ } ) ;
6155
62- it ( `should translate a single string` , ( ) => {
63- const output = run ( `${ cmd } translate ${ toLang } "${ text } "` , cwd ) ;
64- return translate . translate ( text , toLang )
65- . then ( ( results ) => {
66- const expected = `Translations:\n${ text } => (${ toLang } ) ${ results [ 0 ] } ` ;
67- assert . equal ( output , expected ) ;
68- } ) ;
69- } ) ;
56+ test ( `should translate a single string` , async ( t ) => {
57+ const output = await runAsync ( `${ cmd } translate ${ toLang } "${ text } "` , cwd ) ;
58+ const [ translation ] = await translate . translate ( text , toLang ) ;
59+ const expected = `Translations:\n${ text } => (${ toLang } ) ${ translation } ` ;
60+ t . is ( output , expected ) ;
61+ } ) ;
7062
71- it ( `should translate multiple strings` , ( ) => {
72- const output = run ( `${ cmd } translate ${ toLang } "${ text } " "${ text2 } "` , cwd ) ;
73- return translate . translate ( [ text , text2 ] , toLang )
74- . then ( ( results ) => {
75- const expected = `Translations:\n${ text } => (${ toLang } ) ${ results [ 0 ] [ 0 ] } \n${ text2 } => (${ toLang } ) ${ results [ 0 ] [ 1 ] } ` ;
76- assert . equal ( output , expected ) ;
77- } ) ;
78- } ) ;
63+ test ( `should translate multiple strings` , async ( t ) => {
64+ const output = await runAsync ( `${ cmd } translate ${ toLang } "${ text } " "${ text2 } "` , cwd ) ;
65+ const [ translations ] = await translate . translate ( [ text , text2 ] , toLang ) ;
66+ const expected = `Translations:\n${ text } => (${ toLang } ) ${ translations [ 0 ] } \n${ text2 } => (${ toLang } ) ${ translations [ 1 ] } ` ;
67+ t . is ( output , expected ) ;
68+ } ) ;
7969
80- it ( `should translate a single string with a model` , ( ) => {
81- const output = run ( `${ cmd } translate-with-model ${ toLang } ${ model } "${ text } "` , cwd ) ;
82- return translate . translate ( text , toLang )
83- . then ( ( results ) => {
84- const expected = `Translations:\n${ text } => (${ toLang } ) ${ results [ 0 ] } ` ;
85- assert . equal ( output , expected ) ;
86- } ) ;
87- } ) ;
70+ test ( `should translate a single string with a model` , async ( t ) => {
71+ const output = await runAsync ( `${ cmd } translate-with-model ${ toLang } ${ model } "${ text } "` , cwd ) ;
72+ const [ translation ] = await translate . translate ( text , toLang ) ;
73+ const expected = `Translations:\n${ text } => (${ toLang } ) ${ translation } ` ;
74+ t . is ( output , expected ) ;
75+ } ) ;
8876
89- it ( `should translate multiple strings with a model` , ( ) => {
90- const output = run ( `${ cmd } translate-with-model ${ toLang } ${ model } "${ text } " "${ text2 } "` , cwd ) ;
91- return translate . translate ( [ text , text2 ] , toLang )
92- . then ( ( results ) => {
93- const expected = `Translations:\n${ text } => (${ toLang } ) ${ results [ 0 ] [ 0 ] } \n${ text2 } => (${ toLang } ) ${ results [ 0 ] [ 1 ] } ` ;
94- assert . equal ( output , expected ) ;
95- } ) ;
96- } ) ;
77+ test ( `should translate multiple strings with a model` , async ( t ) => {
78+ const output = await runAsync ( `${ cmd } translate-with-model ${ toLang } ${ model } "${ text } " "${ text2 } "` , cwd ) ;
79+ const [ translations ] = await translate . translate ( [ text , text2 ] , toLang ) ;
80+ const expected = `Translations:\n${ text } => (${ toLang } ) ${ translations [ 0 ] } \n${ text2 } => (${ toLang } ) ${ translations [ 1 ] } ` ;
81+ t . is ( output , expected ) ;
9782} ) ;
0 commit comments