diff --git a/translate/.eslintrc.yml b/translate/.eslintrc.yml index 282535f55f6..0aa37ac630e 100644 --- a/translate/.eslintrc.yml +++ b/translate/.eslintrc.yml @@ -1,3 +1,4 @@ --- rules: no-console: off + node/no-missing-require: off diff --git a/translate/package.json b/translate/package.json index 944557f21ba..565009624d6 100644 --- a/translate/package.json +++ b/translate/package.json @@ -8,7 +8,7 @@ "node": ">=8" }, "scripts": { - "test": "mocha system-test --recursive --timeout 90000" + "test": "mocha --recursive --timeout 90000" }, "dependencies": { "@google-cloud/translate": "^3.0.0", @@ -17,7 +17,6 @@ }, "devDependencies": { "chai": "^4.2.0", - "execa": "^1.0.0", "@google-cloud/storage": "^2.4.3", "mocha": "^6.0.0", "uuid": "^3.3.2" diff --git a/translate/system-test/.eslintrc.yml b/translate/test/.eslintrc.yml similarity index 100% rename from translate/system-test/.eslintrc.yml rename to translate/test/.eslintrc.yml diff --git a/translate/system-test/automlTranslation.test.js b/translate/test/automlTranslation.test.js similarity index 78% rename from translate/system-test/automlTranslation.test.js rename to translate/test/automlTranslation.test.js index 2ce9e5c5c92..aafc5a7ebe8 100644 --- a/translate/system-test/automlTranslation.test.js +++ b/translate/test/automlTranslation.test.js @@ -16,17 +16,9 @@ 'use strict'; const {assert} = require('chai'); -const execa = require('execa'); -const path = require('path'); - -const cwd = path.join(__dirname, '..', 'automl'); -const exec = async cmd => { - const res = await execa.shell(cmd, {cwd}); - if (res.stderr) { - throw new Error(res.stderr); - } - return res.stdout; -}; +const cp = require('child_process'); + +const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const cmdDataset = 'node automlTranslationDataset.js'; const cmdModel = 'node automlTranslationModel.js'; @@ -41,11 +33,11 @@ const donotdeleteModelId = 'TRL188026453969732486'; describe.skip('automl sample tests', () => { it(`should create a create, list, and delete a dataset`, async () => { // Check to see that this dataset does not yet exist - let output = await exec(`${cmdDataset} list-datasets`); + let output = execSync(`${cmdDataset} list-datasets`); assert.match(output, new RegExp(testDataSetName)); // Create dataset - output = await exec(`${cmdDataset} create-dataset -n "${testDataSetName}"`); + output = execSync(`${cmdDataset} create-dataset -n "${testDataSetName}"`); const dataSetId = output .split(`\n`)[1] .split(`:`)[1] @@ -56,18 +48,18 @@ describe.skip('automl sample tests', () => { ); // Delete dataset - output = await exec(`${cmdDataset} delete-dataset -i "${dataSetId}"`); + output = execSync(`${cmdDataset} delete-dataset -i "${dataSetId}"`); assert.match(output, /Dataset deleted./); }); // We make two models running this test, see hard-coded workaround below it(`should create a dataset, import data, and start making a model`, async () => { // Check to see that this dataset does not yet exist - let output = await exec(`${cmdDataset} list-datasets`); + let output = execSync(`${cmdDataset} list-datasets`); assert.notMatch(output, new RegExp(dummyDataSet)); // Create dataset - output = await exec(`${cmdDataset} create-dataset -n "${dummyDataSet}"`); + output = execSync(`${cmdDataset} create-dataset -n "${dummyDataSet}"`); const dataSetId = output .split(`\n`)[1] .split(`:`)[1] @@ -75,17 +67,17 @@ describe.skip('automl sample tests', () => { assert.match(output, new RegExp(`Dataset display name: ${dummyDataSet}`)); // Import Data - output = await exec( + output = execSync( `${cmdDataset} import-data -i "${dataSetId}" -p "gs://nodejs-docs-samples-vcm/flowerTraindata20lines.csv"` ); assert.match(output, /Data imported./); // Check to make sure model doesn't already exist - output = await exec(`${cmdModel} list-models`); + output = execSync(`${cmdModel} list-models`); assert.notMatch(output, testModelName); // Begin training dataset, getting operation ID for next operation - output = await exec( + output = execSync( `${cmdModel} create-model -i "${dataSetId}" -m "${testModelName}" -t "2"` ); const operationName = output @@ -95,7 +87,7 @@ describe.skip('automl sample tests', () => { assert.match(output, `Training started...`); // Poll operation status, here confirming that operation is not complete yet - output = await exec( + output = execSync( `${cmdModel} get-operation-status -i "${dataSetId}" -o "${operationName}"` ); assert.match(output, /done: false/); @@ -103,33 +95,33 @@ describe.skip('automl sample tests', () => { it(`should run get model (from a prexisting model)`, async () => { // Confirm dataset exists - let output = await exec(`${cmdDataset} list-datasets`); + let output = execSync(`${cmdDataset} list-datasets`); assert.match(output, /me_do_not_delete/); // List model evaluations, confirm model exists - output = await exec( + output = execSync( `${cmdModel} list-model-evaluations -a "${donotdeleteModelId}"` ); assert.match(output, /translationEvaluationMetrics:/); // Get model evaluation - output = await exec(`${cmdModel} get-model -a "${donotdeleteModelId}"`); + output = execSync(`${cmdModel} get-model -a "${donotdeleteModelId}"`); assert.match(output, /Model deployment state: DEPLOYED/); }); it(`should run Prediction from prexisting model`, async () => { // Confirm dataset exists - let output = await exec(`${cmdDataset} list-datasets`); + let output = execSync(`${cmdDataset} list-datasets`); assert.match(output, /me_do_not_delete/); // List model evaluations, confirm model exists - output = await exec( + output = execSync( `${cmdModel} list-model-evaluations -a "${donotdeleteModelId}"` ); assert.match(output, `translationEvaluationMetrics:`); // Run prediction on 'testImage.jpg' in resources folder - output = await exec( + output = execSync( `${cmdPredict} predict -i "${donotdeleteModelId}" -f "${sampleText}" -t "False"` ); assert.match( @@ -140,7 +132,7 @@ describe.skip('automl sample tests', () => { // List datasets it(`should list datasets`, async () => { - const output = await exec(`${cmdDataset} list-datasets`); + const output = execSync(`${cmdDataset} list-datasets`); assert.match(output, /List of datasets:/); }); }); diff --git a/translate/system-test/quickstart.test.js b/translate/test/quickstart.test.js similarity index 84% rename from translate/system-test/quickstart.test.js rename to translate/test/quickstart.test.js index 8e1688cfb91..36efd92428a 100644 --- a/translate/system-test/quickstart.test.js +++ b/translate/test/quickstart.test.js @@ -16,15 +16,17 @@ 'use strict'; const {assert} = require('chai'); -const execa = require('execa'); +const cp = require('child_process'); const path = require('path'); +const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); + const cwd = path.join(__dirname, '..'); const projectId = process.env.GCLOUD_PROJECT; describe('quickstart sample tests', () => { it('should translate a string', async () => { - const {stdout} = await execa.shell(`node quickstart ${projectId}`, {cwd}); + const stdout = execSync(`node quickstart ${projectId}`, {cwd}); assert.match(stdout, new RegExp('Translation: Привет, мир!')); }); }); diff --git a/translate/system-test/translate.test.js b/translate/test/translate.test.js similarity index 73% rename from translate/system-test/translate.test.js rename to translate/test/translate.test.js index 4cf521434f7..36b99115f59 100644 --- a/translate/system-test/translate.test.js +++ b/translate/test/translate.test.js @@ -15,64 +15,60 @@ 'use strict'; -const path = require('path'); const {assert} = require('chai'); const {Translate} = require('@google-cloud/translate'); -const execa = require('execa'); +const cp = require('child_process'); +const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}).trim(); const translate = new Translate(); - -const cwd = path.join(__dirname, '..'); const cmd = 'node translate.js'; const text = 'Hello world!'; const text2 = 'Goodbye!'; const model = 'nmt'; const toLang = 'ru'; -const exec = async cmd => { - return (await execa.shell(cmd, {cwd})).stdout; -}; - describe('translate sample tests', () => { it('should detect language of a single string', async () => { - const output = await exec(`${cmd} detect "${text}"`); + const output = execSync(`${cmd} detect "${text}"`); const [detection] = await translate.detect(text); - const expected = `Detections:\n${text} => ${detection.language}`; - assert.strictEqual(output, expected); + const expected = new RegExp( + `Detections:\n${text} => ${detection.language}` + ); + assert.match(output, expected); }); it('should detect language of multiple strings', async () => { - const output = await exec(`${cmd} detect "${text}" "${text2}"`, cwd); + const output = execSync(`${cmd} detect "${text}" "${text2}"`); const [detections] = await translate.detect([text, text2]); - const expected = `Detections:\n${text} => ${ - detections[0].language - }\n${text2} => ${detections[1].language}`; - assert.strictEqual(output, expected); + const expected = new RegExp( + `Detections:\n${text} => ${detections[0].language}\n${text2} => ${ + detections[1].language + }` + ); + assert.match(output, expected); }); - it('should list languages', async () => { - const output = await exec(`${cmd} list`); + it('should list languages', () => { + const output = execSync(`${cmd} list`); assert.match(output, /Languages:/); assert.match(output, new RegExp(`{ code: 'af', name: 'Afrikaans' }`)); }); - it('should list languages with a target', async () => { - const output = await exec(`${cmd} list es`); + it('should list languages with a target', () => { + const output = execSync(`${cmd} list es`); assert.match(output, /Languages:/); assert.match(output, new RegExp(`{ code: 'af', name: 'afrikáans' }`)); }); it('should translate a single string', async () => { - const output = await exec(`${cmd} translate ${toLang} "${text}"`); + const output = execSync(`${cmd} translate ${toLang} "${text}"`); const [translation] = await translate.translate(text, toLang); const expected = `Translations:\n${text} => (${toLang}) ${translation}`; assert.strictEqual(output, expected); }); it('should translate multiple strings', async () => { - const output = await exec( - `${cmd} translate ${toLang} "${text}" "${text2}"` - ); + const output = execSync(`${cmd} translate ${toLang} "${text}" "${text2}"`); const [translations] = await translate.translate([text, text2], toLang); const expected = `Translations:\n${text} => (${toLang}) ${ translations[0] @@ -81,7 +77,7 @@ describe('translate sample tests', () => { }); it('should translate a single string with a model', async () => { - const output = await exec( + const output = execSync( `${cmd} translate-with-model ${toLang} ${model} "${text}"` ); const [translation] = await translate.translate(text, toLang); @@ -90,7 +86,7 @@ describe('translate sample tests', () => { }); it('should translate multiple strings with a model', async () => { - const output = await exec( + const output = execSync( `${cmd} translate-with-model ${toLang} ${model} "${text}" "${text2}"` ); const [translations] = await translate.translate([text, text2], toLang); diff --git a/translate/system-test/v3beta1/translate_batch_translate_text_beta.test.js b/translate/test/v3beta1/translate_batch_translate_text_beta.test.js similarity index 94% rename from translate/system-test/v3beta1/translate_batch_translate_text_beta.test.js rename to translate/test/v3beta1/translate_batch_translate_text_beta.test.js index de545c0b427..c3044a49951 100644 --- a/translate/system-test/v3beta1/translate_batch_translate_text_beta.test.js +++ b/translate/test/v3beta1/translate_batch_translate_text_beta.test.js @@ -18,9 +18,10 @@ const {assert} = require('chai'); const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1; const {Storage} = require('@google-cloud/storage'); -const execa = require('execa'); +const cp = require('child_process'); const uuid = require('uuid'); -const exec = async cmd => (await execa.shell(cmd)).stdout; + +const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const REGION_TAG = 'translate_batch_translate_text_beta'; @@ -53,7 +54,7 @@ describe(REGION_TAG, () => { const inputUri = `gs://cloud-samples-data/translation/text.txt`; const outputUri = `gs://${projectId}/${bucketName}`; - const output = await exec( + const output = execSync( `node v3beta1/${REGION_TAG}.js ${projectId} ${location} ${inputUri} ${outputUri}` ); assert.match(output, /Total Characters: 13/); diff --git a/translate/system-test/v3beta1/translate_create_glossary_beta.test.js b/translate/test/v3beta1/translate_create_glossary_beta.test.js similarity index 93% rename from translate/system-test/v3beta1/translate_create_glossary_beta.test.js rename to translate/test/v3beta1/translate_create_glossary_beta.test.js index d8008760550..74c9b2764bb 100644 --- a/translate/system-test/v3beta1/translate_create_glossary_beta.test.js +++ b/translate/test/v3beta1/translate_create_glossary_beta.test.js @@ -17,8 +17,9 @@ const {assert} = require('chai'); const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1; -const execa = require('execa'); -const exec = async cmd => (await execa.shell(cmd)).stdout; +const cp = require('child_process'); + +const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const REGION_TAG = 'translate_create_glossary_beta'; @@ -29,7 +30,7 @@ describe(REGION_TAG, () => { const projectId = await translationClient.getProjectId(); const location = 'us-central1'; const glossaryId = 'test-glossary'; - const output = await exec( + const output = execSync( `node v3beta1/${REGION_TAG}.js ${projectId} ${location} ${glossaryId}` ); assert.match( diff --git a/translate/system-test/v3beta1/translate_delete_glossary_beta.test.js b/translate/test/v3beta1/translate_delete_glossary_beta.test.js similarity index 94% rename from translate/system-test/v3beta1/translate_delete_glossary_beta.test.js rename to translate/test/v3beta1/translate_delete_glossary_beta.test.js index 82c93eca0ed..55e13124854 100644 --- a/translate/system-test/v3beta1/translate_delete_glossary_beta.test.js +++ b/translate/test/v3beta1/translate_delete_glossary_beta.test.js @@ -17,8 +17,9 @@ const {assert} = require('chai'); const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1; -const execa = require('execa'); -const exec = async cmd => (await execa.shell(cmd)).stdout; +const cp = require('child_process'); + +const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const REGION_TAG = 'translate_delete_glossary_beta'; @@ -60,7 +61,7 @@ describe(REGION_TAG, () => { it('should delete a glossary', async () => { const projectId = await translationClient.getProjectId(); - const output = await exec( + const output = execSync( `node v3beta1/${REGION_TAG}.js ${projectId} ${location} ${glossaryId}` ); assert.match(output, /glossary/); diff --git a/translate/system-test/v3beta1/translate_detect_language_beta.test.js b/translate/test/v3beta1/translate_detect_language_beta.test.js similarity index 90% rename from translate/system-test/v3beta1/translate_detect_language_beta.test.js rename to translate/test/v3beta1/translate_detect_language_beta.test.js index 34a8adb4ff7..8e435c81710 100644 --- a/translate/system-test/v3beta1/translate_detect_language_beta.test.js +++ b/translate/test/v3beta1/translate_detect_language_beta.test.js @@ -17,8 +17,9 @@ const {assert} = require('chai'); const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1; -const execa = require('execa'); -const exec = async cmd => (await execa.shell(cmd)).stdout; +const cp = require('child_process'); + +const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const REGION_TAG = 'translate_detect_language_beta'; @@ -28,7 +29,7 @@ describe(REGION_TAG, () => { const projectId = await translationClient.getProjectId(); const location = 'global'; const text = `'Hæ sæta'`; - const output = await exec( + const output = execSync( `node v3beta1/${REGION_TAG}.js ${projectId} ${location} ${text}` ); assert.match(output, /Language Code: is/); diff --git a/translate/system-test/v3beta1/translate_get_glossary_beta.test.js b/translate/test/v3beta1/translate_get_glossary_beta.test.js similarity index 95% rename from translate/system-test/v3beta1/translate_get_glossary_beta.test.js rename to translate/test/v3beta1/translate_get_glossary_beta.test.js index decc19e4473..7e1dd44ae96 100644 --- a/translate/system-test/v3beta1/translate_get_glossary_beta.test.js +++ b/translate/test/v3beta1/translate_get_glossary_beta.test.js @@ -17,8 +17,9 @@ const {assert} = require('chai'); const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1; -const execa = require('execa'); -const exec = async cmd => (await execa.shell(cmd)).stdout; +const cp = require('child_process'); + +const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const REGION_TAG = 'translate_get_glossary_beta'; @@ -59,7 +60,7 @@ describe(REGION_TAG, () => { it('should get a glossary', async () => { const projectId = await translationClient.getProjectId(); - const output = await exec( + const output = execSync( `node v3beta1/${REGION_TAG}.js ${projectId} ${location} ${glossaryId}` ); assert.match(output, /test-glossary/); diff --git a/translate/system-test/v3beta1/translate_list_codes_beta.test.js b/translate/test/v3beta1/translate_list_codes_beta.test.js similarity index 86% rename from translate/system-test/v3beta1/translate_list_codes_beta.test.js rename to translate/test/v3beta1/translate_list_codes_beta.test.js index dab4f2cc69c..f54561123ce 100644 --- a/translate/system-test/v3beta1/translate_list_codes_beta.test.js +++ b/translate/test/v3beta1/translate_list_codes_beta.test.js @@ -17,8 +17,9 @@ const {assert} = require('chai'); const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1; -const execa = require('execa'); -const exec = async cmd => (await execa.shell(cmd)).stdout; +const cp = require('child_process'); + +const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const REGION_TAG = 'translate_list_codes_beta'; @@ -26,7 +27,7 @@ describe(REGION_TAG, () => { it('should list available language codes', async () => { const translationClient = new TranslationServiceClient(); const projectId = await translationClient.getProjectId(); - const output = await exec(`node v3beta1/${REGION_TAG}.js ${projectId}`); + const output = execSync(`node v3beta1/${REGION_TAG}.js ${projectId}`); assert.match(output, /Language Code: en/); assert.match(output, /Language Code: fr/); }); diff --git a/translate/system-test/v3beta1/translate_list_glossary_beta.test.js b/translate/test/v3beta1/translate_list_glossary_beta.test.js similarity index 95% rename from translate/system-test/v3beta1/translate_list_glossary_beta.test.js rename to translate/test/v3beta1/translate_list_glossary_beta.test.js index f3d738e4220..7b9a2fc6052 100644 --- a/translate/system-test/v3beta1/translate_list_glossary_beta.test.js +++ b/translate/test/v3beta1/translate_list_glossary_beta.test.js @@ -17,8 +17,9 @@ const {assert} = require('chai'); const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1; -const execa = require('execa'); -const exec = async cmd => (await execa.shell(cmd)).stdout; +const cp = require('child_process'); + +const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const REGION_TAG = 'translate_list_glossary_beta'; @@ -59,7 +60,7 @@ describe(REGION_TAG, () => { it('should list glossaries in project', async () => { const projectId = await translationClient.getProjectId(); - const output = await exec( + const output = execSync( `node v3beta1/${REGION_TAG}.js ${projectId} ${location}` ); assert.match( diff --git a/translate/system-test/v3beta1/translate_list_language_names_beta.test.js b/translate/test/v3beta1/translate_list_language_names_beta.test.js similarity index 87% rename from translate/system-test/v3beta1/translate_list_language_names_beta.test.js rename to translate/test/v3beta1/translate_list_language_names_beta.test.js index b81d6ee87b8..4cbb828472b 100644 --- a/translate/system-test/v3beta1/translate_list_language_names_beta.test.js +++ b/translate/test/v3beta1/translate_list_language_names_beta.test.js @@ -17,8 +17,9 @@ const {assert} = require('chai'); const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1; -const execa = require('execa'); -const exec = async cmd => (await execa.shell(cmd)).stdout; +const cp = require('child_process'); + +const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const REGION_TAG = 'translate_list_language_names_beta'; @@ -26,7 +27,7 @@ describe(REGION_TAG, () => { it('should list available language names', async () => { const translationClient = new TranslationServiceClient(); const projectId = await translationClient.getProjectId(); - const output = await exec(`node v3beta1/${REGION_TAG}.js ${projectId}`); + const output = execSync(`node v3beta1/${REGION_TAG}.js ${projectId}`); assert.match(output, /Language Code: en/); assert.match(output, /Display Name: Anglais/); assert.match(output, /Language Code: fr/); diff --git a/translate/system-test/v3beta1/translate_translate_text_beta.test.js b/translate/test/v3beta1/translate_translate_text_beta.test.js similarity index 90% rename from translate/system-test/v3beta1/translate_translate_text_beta.test.js rename to translate/test/v3beta1/translate_translate_text_beta.test.js index 3b5b3ece817..556e706f74a 100644 --- a/translate/system-test/v3beta1/translate_translate_text_beta.test.js +++ b/translate/test/v3beta1/translate_translate_text_beta.test.js @@ -17,8 +17,9 @@ const {assert} = require('chai'); const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1; -const execa = require('execa'); -const exec = async cmd => (await execa.shell(cmd)).stdout; +const cp = require('child_process'); + +const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const REGION_TAG = 'translate_translate_text_beta'; @@ -28,7 +29,7 @@ describe(REGION_TAG, () => { const projectId = await translationClient.getProjectId(); const location = `global`; const text = `"Hello world"`; - const output = await exec( + const output = execSync( `node v3beta1/${REGION_TAG}.js ${projectId} ${location} ${text}` ); assert.match(output, /Translation: Zdravo svet/); diff --git a/translate/system-test/v3beta1/translate_translate_text_with_glossary_beta.test.js b/translate/test/v3beta1/translate_translate_text_with_glossary_beta.test.js similarity index 95% rename from translate/system-test/v3beta1/translate_translate_text_with_glossary_beta.test.js rename to translate/test/v3beta1/translate_translate_text_with_glossary_beta.test.js index 451932a4f62..529c8e3f195 100644 --- a/translate/system-test/v3beta1/translate_translate_text_with_glossary_beta.test.js +++ b/translate/test/v3beta1/translate_translate_text_with_glossary_beta.test.js @@ -17,8 +17,9 @@ const {assert} = require('chai'); const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1; -const execa = require('execa'); -const exec = async cmd => (await execa.shell(cmd)).stdout; +const cp = require('child_process'); + +const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const REGION_TAG = 'translate_translate_text_with_glossary_beta'; @@ -60,7 +61,7 @@ describe(REGION_TAG, () => { it('should translate text with a glossary in project', async () => { const projectId = await translationClient.getProjectId(); const input = 'directions'; - const output = await exec( + const output = execSync( `node v3beta1/${REGION_TAG}.js ${projectId} ${location} ${glossaryId} ${input}` ); assert.match(output, /direcciones/);