@@ -26,7 +26,7 @@ const fetch = require('node-fetch')
2626const crossZip = require ( 'cross-zip' )
2727const ora = require ( 'ora' )
2828
29- const { mkdir } = promises
29+ const { mkdir, cp } = promises
3030const pipeline = promisify ( stream . pipeline )
3131const unzip = promisify ( crossZip . unzip )
3232
@@ -35,7 +35,7 @@ const zipFile = join(__dirname, '..', 'serverless-clients-tests.zip')
3535
3636const specFolder = join ( __dirname , '..' , 'rest-api-spec' )
3737
38- async function downloadArtifacts ( ) {
38+ async function downloadArtifacts ( localTests ) {
3939 const log = ora ( 'Checking out spec and test' ) . start ( )
4040
4141 const { GITHUB_TOKEN } = process . env
@@ -46,31 +46,36 @@ async function downloadArtifacts () {
4646
4747 log . text = 'Fetching test YAML files'
4848
49- if ( ! GITHUB_TOKEN ) {
50- log . fail ( "Missing required environment variable 'GITHUB_TOKEN'" )
51- process . exit ( 1 )
52- }
53-
54- let response = await fetch ( 'https://api.github.com/repos/elastic/serverless-clients-tests/zipball/main' , {
55- headers : {
56- Authorization : `Bearer ${ GITHUB_TOKEN } ` ,
57- Accept : "application/vnd.github+json" ,
49+ if ( localTests ) {
50+ log . text = `Copying local tests from ${ localTests } `
51+ await cp ( localTests , testYamlFolder , { recursive : true } )
52+ } else {
53+ if ( ! GITHUB_TOKEN ) {
54+ log . fail ( "Missing required environment variable 'GITHUB_TOKEN'" )
55+ process . exit ( 1 )
5856 }
59- } )
6057
61- if ( ! response . ok ) {
62- log . fail ( `unexpected response ${ response . statusText } ` )
63- process . exit ( 1 )
64- }
58+ let response = await fetch ( 'https://api.github.com/repos/elastic/serverless-clients-tests/zipball/main' , {
59+ headers : {
60+ Authorization : `Bearer ${ GITHUB_TOKEN } ` ,
61+ Accept : "application/vnd.github+json" ,
62+ }
63+ } )
6564
66- log . text = 'Downloading tests zipball'
67- await pipeline ( response . body , createWriteStream ( zipFile ) )
65+ if ( ! response . ok ) {
66+ log . fail ( `unexpected response ${ response . statusText } ` )
67+ process . exit ( 1 )
68+ }
6869
69- log . text = 'Unzipping tests'
70- await unzip ( zipFile , testYamlFolder )
70+ log . text = 'Downloading tests zipball '
71+ await pipeline ( response . body , createWriteStream ( zipFile ) )
7172
72- log . text = 'Cleanup'
73- await rimraf ( zipFile )
73+ log . text = 'Unzipping tests'
74+ await unzip ( zipFile , testYamlFolder )
75+
76+ log . text = 'Cleanup'
77+ await rimraf ( zipFile )
78+ }
7479
7580 log . text = 'Fetching Elasticsearch spec info'
7681 await rimraf ( specFolder )
0 commit comments