16
16
'use strict' ;
17
17
18
18
const { assert} = require ( 'chai' ) ;
19
- const execa = require ( 'execa' ) ;
20
- const path = require ( 'path' ) ;
21
-
22
- const cwd = path . join ( __dirname , '..' , 'automl' ) ;
23
- const exec = async cmd => {
24
- const res = await execa . shell ( cmd , { cwd} ) ;
25
- if ( res . stderr ) {
26
- throw new Error ( res . stderr ) ;
27
- }
28
- return res . stdout ;
29
- } ;
19
+ const cp = require ( 'child_process' ) ;
20
+
21
+ const execSync = cmd => cp . execSync ( cmd , { encoding : 'utf-8' } ) ;
30
22
31
23
const cmdDataset = 'node automlTranslationDataset.js' ;
32
24
const cmdModel = 'node automlTranslationModel.js' ;
@@ -41,11 +33,11 @@ const donotdeleteModelId = 'TRL188026453969732486';
41
33
describe . skip ( 'automl sample tests' , ( ) => {
42
34
it ( `should create a create, list, and delete a dataset` , async ( ) => {
43
35
// Check to see that this dataset does not yet exist
44
- let output = await exec ( `${ cmdDataset } list-datasets` ) ;
36
+ let output = execSync ( `${ cmdDataset } list-datasets` ) ;
45
37
assert . match ( output , new RegExp ( testDataSetName ) ) ;
46
38
47
39
// Create dataset
48
- output = await exec ( `${ cmdDataset } create-dataset -n "${ testDataSetName } "` ) ;
40
+ output = execSync ( `${ cmdDataset } create-dataset -n "${ testDataSetName } "` ) ;
49
41
const dataSetId = output
50
42
. split ( `\n` ) [ 1 ]
51
43
. split ( `:` ) [ 1 ]
@@ -56,36 +48,36 @@ describe.skip('automl sample tests', () => {
56
48
) ;
57
49
58
50
// Delete dataset
59
- output = await exec ( `${ cmdDataset } delete-dataset -i "${ dataSetId } "` ) ;
51
+ output = execSync ( `${ cmdDataset } delete-dataset -i "${ dataSetId } "` ) ;
60
52
assert . match ( output , / D a t a s e t d e l e t e d ./ ) ;
61
53
} ) ;
62
54
63
55
// We make two models running this test, see hard-coded workaround below
64
56
it ( `should create a dataset, import data, and start making a model` , async ( ) => {
65
57
// Check to see that this dataset does not yet exist
66
- let output = await exec ( `${ cmdDataset } list-datasets` ) ;
58
+ let output = execSync ( `${ cmdDataset } list-datasets` ) ;
67
59
assert . notMatch ( output , new RegExp ( dummyDataSet ) ) ;
68
60
69
61
// Create dataset
70
- output = await exec ( `${ cmdDataset } create-dataset -n "${ dummyDataSet } "` ) ;
62
+ output = execSync ( `${ cmdDataset } create-dataset -n "${ dummyDataSet } "` ) ;
71
63
const dataSetId = output
72
64
. split ( `\n` ) [ 1 ]
73
65
. split ( `:` ) [ 1 ]
74
66
. trim ( ) ;
75
67
assert . match ( output , new RegExp ( `Dataset display name: ${ dummyDataSet } ` ) ) ;
76
68
77
69
// Import Data
78
- output = await exec (
70
+ output = execSync (
79
71
`${ cmdDataset } import-data -i "${ dataSetId } " -p "gs://nodejs-docs-samples-vcm/flowerTraindata20lines.csv"`
80
72
) ;
81
73
assert . match ( output , / D a t a i m p o r t e d ./ ) ;
82
74
83
75
// Check to make sure model doesn't already exist
84
- output = await exec ( `${ cmdModel } list-models` ) ;
76
+ output = execSync ( `${ cmdModel } list-models` ) ;
85
77
assert . notMatch ( output , testModelName ) ;
86
78
87
79
// Begin training dataset, getting operation ID for next operation
88
- output = await exec (
80
+ output = execSync (
89
81
`${ cmdModel } create-model -i "${ dataSetId } " -m "${ testModelName } " -t "2"`
90
82
) ;
91
83
const operationName = output
@@ -95,41 +87,41 @@ describe.skip('automl sample tests', () => {
95
87
assert . match ( output , `Training started...` ) ;
96
88
97
89
// Poll operation status, here confirming that operation is not complete yet
98
- output = await exec (
90
+ output = execSync (
99
91
`${ cmdModel } get-operation-status -i "${ dataSetId } " -o "${ operationName } "`
100
92
) ;
101
93
assert . match ( output , / d o n e : f a l s e / ) ;
102
94
} ) ;
103
95
104
96
it ( `should run get model (from a prexisting model)` , async ( ) => {
105
97
// Confirm dataset exists
106
- let output = await exec ( `${ cmdDataset } list-datasets` ) ;
98
+ let output = execSync ( `${ cmdDataset } list-datasets` ) ;
107
99
assert . match ( output , / m e _ d o _ n o t _ d e l e t e / ) ;
108
100
109
101
// List model evaluations, confirm model exists
110
- output = await exec (
102
+ output = execSync (
111
103
`${ cmdModel } list-model-evaluations -a "${ donotdeleteModelId } "`
112
104
) ;
113
105
assert . match ( output , / t r a n s l a t i o n E v a l u a t i o n M e t r i c s : / ) ;
114
106
115
107
// Get model evaluation
116
- output = await exec ( `${ cmdModel } get-model -a "${ donotdeleteModelId } "` ) ;
108
+ output = execSync ( `${ cmdModel } get-model -a "${ donotdeleteModelId } "` ) ;
117
109
assert . match ( output , / M o d e l d e p l o y m e n t s t a t e : D E P L O Y E D / ) ;
118
110
} ) ;
119
111
120
112
it ( `should run Prediction from prexisting model` , async ( ) => {
121
113
// Confirm dataset exists
122
- let output = await exec ( `${ cmdDataset } list-datasets` ) ;
114
+ let output = execSync ( `${ cmdDataset } list-datasets` ) ;
123
115
assert . match ( output , / m e _ d o _ n o t _ d e l e t e / ) ;
124
116
125
117
// List model evaluations, confirm model exists
126
- output = await exec (
118
+ output = execSync (
127
119
`${ cmdModel } list-model-evaluations -a "${ donotdeleteModelId } "`
128
120
) ;
129
121
assert . match ( output , `translationEvaluationMetrics:` ) ;
130
122
131
123
// Run prediction on 'testImage.jpg' in resources folder
132
- output = await exec (
124
+ output = execSync (
133
125
`${ cmdPredict } predict -i "${ donotdeleteModelId } " -f "${ sampleText } " -t "False"`
134
126
) ;
135
127
assert . match (
@@ -140,7 +132,7 @@ describe.skip('automl sample tests', () => {
140
132
141
133
// List datasets
142
134
it ( `should list datasets` , async ( ) => {
143
- const output = await exec ( `${ cmdDataset } list-datasets` ) ;
135
+ const output = execSync ( `${ cmdDataset } list-datasets` ) ;
144
136
assert . match ( output , / L i s t o f d a t a s e t s : / ) ;
145
137
} ) ;
146
138
} ) ;
0 commit comments