@@ -22,45 +22,57 @@ const run = require(`../../utils`).run;
2222const cwd = path . join ( __dirname , `..` ) ;
2323const cmd = `node translate.js` ;
2424const text = `Hello world!` ;
25+ const text2 = `Goodbye!` ;
2526const toLang = `ru` ;
2627
2728describe ( `translate:translate` , ( ) => {
28- const translate = Translate ( {
29- key : process . env . TRANSLATE_API_KEY
30- } ) ;
31- if ( ! process . env . TRANSLATE_API_KEY ) {
32- process . stdout . write ( `Skipping Translate API tests...\n` ) ;
33- return ;
34- }
29+ const translate = Translate ( ) ;
3530
36- it ( `should detect language` , ( done ) => {
31+ it ( `should detect language of a single string ` , ( ) => {
3732 const output = run ( `${ cmd } detect "${ text } "` , cwd ) ;
38- translate . detect ( text , ( err , result ) => {
39- assert . ifError ( err ) ;
40- assert . equal ( output , `Detected: ${ JSON . stringify ( result ) } ` ) ;
41- done ( ) ;
42- } ) ;
33+ return translate . detect ( text )
34+ . then ( ( results ) => {
35+ const expected = `Detections:\n${ text } => ${ results [ 0 ] . language } ` ;
36+ assert . equal ( output , expected ) ;
37+ } ) ;
38+ } ) ;
39+
40+ it ( `should detect language of multiple strings` , ( ) => {
41+ const output = run ( `${ cmd } detect "${ text } " "${ text2 } "` , cwd ) ;
42+ return translate . detect ( [ text , text2 ] )
43+ . then ( ( results ) => {
44+ const expected = `Detections:\n${ text } => ${ results [ 0 ] [ 0 ] . language } \n${ text2 } => ${ results [ 0 ] [ 1 ] . language } ` ;
45+ assert . equal ( output , expected ) ;
46+ } ) ;
4347 } ) ;
4448
4549 it ( `should list languages` , ( ) => {
4650 const output = run ( `${ cmd } list` , cwd ) ;
47- assert . notEqual ( output . indexOf ( `Languages:` ) , - 1 ) ;
48- assert . notEqual ( output . indexOf ( `{ code: 'af', name: 'Afrikaans' }` ) , - 1 ) ;
51+ assert . equal ( output . includes ( `Languages:` ) , true ) ;
52+ assert . equal ( output . includes ( `{ code: 'af', name: 'Afrikaans' }` ) , true ) ;
4953 } ) ;
5054
5155 it ( `should list languages with a target` , ( ) => {
5256 const output = run ( `${ cmd } list es` , cwd ) ;
53- assert . notEqual ( output . indexOf ( `Languages:` ) , - 1 ) ;
54- assert . notEqual ( output . indexOf ( `{ code: 'af', name: 'afrikáans' }` ) , - 1 ) ;
57+ assert . equal ( output . includes ( `Languages:` ) , true ) ;
58+ assert . equal ( output . includes ( `{ code: 'af', name: 'afrikáans' }` ) , true ) ;
5559 } ) ;
5660
57- it ( `should translate text ` , ( done ) => {
61+ it ( `should translate a single string ` , ( ) => {
5862 const output = run ( `${ cmd } translate ${ toLang } "${ text } "` , cwd ) ;
59- translate . translate ( text , toLang , ( err , translation ) => {
60- assert . ifError ( err ) ;
61- assert . notEqual ( output . indexOf ( `Text: ["${ text } "]` ) , - 1 ) ;
62- assert . notEqual ( output . indexOf ( `Translation: "${ translation } "` ) , - 1 ) ;
63- done ( ) ;
64- } ) ;
63+ return translate . translate ( text , toLang )
64+ . then ( ( results ) => {
65+ const expected = `Translations:\n${ text } => (${ toLang } ) ${ results [ 0 ] } ` ;
66+ assert . equal ( output , expected ) ;
67+ } ) ;
68+ } ) ;
69+
70+ it ( `should translate multiple strings` , ( ) => {
71+ const output = run ( `${ cmd } translate ${ toLang } "${ text } " "${ text2 } "` , cwd ) ;
72+ return translate . translate ( [ text , text2 ] , toLang )
73+ . then ( ( results ) => {
74+ const expected = `Translations:\n${ text } => (${ toLang } ) ${ results [ 0 ] [ 0 ] } \n${ text2 } => (${ toLang } ) ${ results [ 0 ] [ 1 ] } ` ;
75+ assert . equal ( output , expected ) ;
76+ } ) ;
6577 } ) ;
6678} ) ;
0 commit comments