@@ -19,7 +19,7 @@ const path = require('path');
19
19
const assert = require ( 'assert' ) ;
20
20
const { v4 : uuidv4 } = require ( 'uuid' ) ;
21
21
const { execSync} = require ( 'child_process' ) ;
22
- const { describe, it, before, after} = require ( 'mocha' ) ;
22
+ const { describe, it, before, after, afterEach } = require ( 'mocha' ) ;
23
23
24
24
const { Storage} = require ( '@google-cloud/storage' ) ;
25
25
const uniqueID = uuidv4 ( ) . split ( '-' ) [ 0 ] ;
@@ -151,47 +151,51 @@ describe('Job template functions', () => {
151
151
} ) ;
152
152
153
153
describe ( 'Job functions preset' , ( ) => {
154
- before ( function ( ) {
154
+ let presetJobId ;
155
+ function createJobFromPreset ( ) {
155
156
const output = execSync (
156
157
`node createJobFromPreset.js ${ projectId } ${ location } ${ inputUri } ${ outputUriForPreset } ${ preset } ` ,
157
158
{ cwd}
158
159
) ;
159
160
assert . ok (
160
161
output . includes ( `projects/${ projectNumber } /locations/${ location } /jobs/` )
161
162
) ;
162
- this . presetJobId = output . toString ( ) . split ( '/' ) . pop ( ) ;
163
- } ) ;
163
+ presetJobId = output . toString ( ) . split ( '/' ) . pop ( ) ;
164
+ }
164
165
165
- after ( function ( ) {
166
+ afterEach ( ( ) => {
166
167
const output = execSync (
167
- `node deleteJob.js ${ projectId } ${ location } ${ this . presetJobId } ` ,
168
+ `node deleteJob.js ${ projectId } ${ location } ${ presetJobId } ` ,
168
169
{ cwd}
169
170
) ;
170
171
assert . ok ( output . includes ( 'Deleted job' ) ) ;
171
172
} ) ;
172
173
173
- it ( 'should get a job' , function ( ) {
174
+ it ( 'should get a job' , ( ) => {
175
+ createJobFromPreset ( ) ;
174
176
const output = execSync (
175
- `node getJob.js ${ projectId } ${ location } ${ this . presetJobId } ` ,
177
+ `node getJob.js ${ projectId } ${ location } ${ presetJobId } ` ,
176
178
{ cwd}
177
179
) ;
178
- const jobName = `projects/${ projectNumber } /locations/${ location } /jobs/${ this . presetJobId } ` ;
180
+ const jobName = `projects/${ projectNumber } /locations/${ location } /jobs/${ presetJobId } ` ;
179
181
assert . ok ( output . includes ( jobName ) ) ;
180
182
} ) ;
181
183
182
- it ( 'should show a list of jobs' , function ( ) {
184
+ it ( 'should show a list of jobs' , ( ) => {
185
+ createJobFromPreset ( ) ;
183
186
const output = execSync ( `node listJobs.js ${ projectId } ${ location } ` , {
184
187
cwd,
185
188
} ) ;
186
- const jobName = `projects/${ projectNumber } /locations/${ location } /jobs/${ this . presetJobId } ` ;
189
+ const jobName = `projects/${ projectNumber } /locations/${ location } /jobs/${ presetJobId } ` ;
187
190
assert . ok ( output . includes ( jobName ) ) ;
188
191
} ) ;
189
192
190
193
it ( 'should check that the job succeeded' , async function ( ) {
191
194
this . retries ( 5 ) ;
195
+ createJobFromPreset ( ) ;
192
196
await wait ( 90000 ) ;
193
197
const output = execSync (
194
- `node getJobState.js ${ projectId } ${ location } ${ this . presetJobId } ` ,
198
+ `node getJobState.js ${ projectId } ${ location } ${ presetJobId } ` ,
195
199
{ cwd}
196
200
) ;
197
201
assert . ok ( output . includes ( 'Job state: SUCCEEDED' ) ) ;
0 commit comments