1- const fs = require ( 'fs' ) ;
2- const asyncForEach = require ( './utils/foreach' )
3- const waitFor = require ( './utils/wait' )
4- const writeTest = require ( './component/tests' )
5- const writePages = require ( './component/pages' )
6- const writeRunner = require ( './component/runner' )
7- const writeJsonSchema = require ( './component/json_schema' )
8- const writeHelper = require ( './component/helper' )
9- const writeData = require ( './component/data' )
1+ import fs from 'fs'
2+ import asyncForEach from './utils/foreach.js'
3+ import waitFor from './utils/wait.js'
4+ import writeTest from './component/tests.js'
5+ import writePages from './component/pages.js'
6+ import writeData from './component/data.js'
7+ import writeRunner from './component/runner.js'
8+ import writeHelper from './component/helper.js'
9+ import writeJsonSchema from './component/json_schema.js'
1010
1111// main generator
1212async function generate ( file ) {
@@ -20,7 +20,7 @@ async function generate(file) {
2020 writeHelper ( )
2121
2222 // write .example.env file
23- fs . writeFile ( '.example.env' , 'APP_URL =your_api_url' , function ( err ) { if ( err ) throw err ; } ) ;
23+ fs . writeFile ( '.example.env' , 'DEV_MAIN =your_api_url' , function ( err ) { if ( err ) throw err ; } ) ;
2424
2525 asyncForEach ( items , async ( element ) => {
2626 // console.log(element);
@@ -31,6 +31,8 @@ async function generate(file) {
3131 const testPath = 'tests/scenarios/' + element . name ;
3232 const testRelativePath = '../tests/scenarios/' + element . name ;
3333 fs . mkdirSync ( testPath , { recursive : true } )
34+ // main pages path
35+ const mainpagesPath = '../main.pages' ;
3436 // write pages dir
3537 const pagesPath = 'tests/pages/' + element . name ;
3638 const pagesPathRelativePath = '../../pages/' + element . name ;
@@ -47,7 +49,7 @@ async function generate(file) {
4749 asyncForEach ( element . item , async ( second ) => {
4850 if ( second . hasOwnProperty ( 'item' ) == false ) {
4951 writeTest ( second , testPath , pagesPathRelativePath )
50- writePages ( second , pagesPath , jsonSchemaRelativePath , helperPath )
52+ writePages ( second , pagesPath , jsonSchemaRelativePath , helperPath , mainpagesPath )
5153 writeJsonSchema ( second , jsonSchemaPath )
5254 await waitFor ( 10 )
5355 } else {
@@ -59,6 +61,7 @@ async function generate(file) {
5961 const third_sch = jsonSchemaPath + '/' + second . name ;
6062 const third_schRe = '../' + jsonSchemaRelativePath + '/' + second . name ;
6163 const third_helpRe = '../' + helperPath ;
64+ const third_mainRe = '../' + mainpagesPath ;
6265 const third_runPath = runPath + '/' + element . name ;
6366
6467 fs . mkdirSync ( third_test + '/' , { recursive : true } )
@@ -68,7 +71,7 @@ async function generate(file) {
6871 writeRunner ( second , third_testRe , third_runPath )
6972 if ( third . hasOwnProperty ( 'item' ) == false ) {
7073 writeTest ( third , third_test , third_pageRe )
71- writePages ( third , third_page , third_schRe , third_helpRe )
74+ writePages ( third , third_page , third_schRe , third_helpRe , third_mainRe )
7275 writeJsonSchema ( third , third_sch )
7376 await waitFor ( 10 )
7477 } else {
@@ -80,6 +83,7 @@ async function generate(file) {
8083 const fourth_sch = third_sch + '/' + third . name ;
8184 const fourth_schRe = '../' + third_schRe + '/' + third . name ;
8285 const fourth_helpRe = '../' + third_helpRe ;
86+ const fourth_mainRe = '../' + third_mainRe ;
8387 const fourth_runPath = third_runPath + '/' + second . name ;
8488
8589 fs . mkdirSync ( fourth_test + '/' , { recursive : true } )
@@ -89,7 +93,7 @@ async function generate(file) {
8993 writeRunner ( third , fourth_testRe , fourth_runPath )
9094 if ( fourth . hasOwnProperty ( 'item' ) == false ) {
9195 writeTest ( fourth , fourth_test , fourth_pageRe )
92- writePages ( fourth , fourth_page , fourth_schRe , fourth_helpRe )
96+ writePages ( fourth , fourth_page , fourth_schRe , fourth_helpRe , fourth_mainRe )
9397 writeJsonSchema ( fourth , fourth_sch )
9498 await waitFor ( 10 )
9599 } else {
@@ -101,6 +105,7 @@ async function generate(file) {
101105 const fifth_sch = fourth_sch + '/' + fourth . name ;
102106 const fifth_schRe = '../' + fourth_schRe + '/' + fourth . name ;
103107 const fifth_helpRe = '../' + fourth_helpRe ;
108+ const fifth_mainRe = '../' + fourth_mainRe ;
104109 const fifth_runPath = fourth_runPath + '/' + third . name ;
105110
106111 fs . mkdirSync ( fifth_test + '/' , { recursive : true } )
@@ -111,7 +116,7 @@ async function generate(file) {
111116 await waitFor ( 50 )
112117 if ( fifth . hasOwnProperty ( 'item' ) == false ) {
113118 writeTest ( fifth , fifth_test , fifth_pageRe )
114- writePages ( fifth , fifth_page , fifth_schRe , fifth_helpRe )
119+ writePages ( fifth , fifth_page , fifth_schRe , fifth_helpRe , fifth_mainRe )
115120 writeJsonSchema ( fifth , fifth_sch )
116121 await waitFor ( 10 )
117122 } else {
@@ -123,6 +128,7 @@ async function generate(file) {
123128 const sixth_sch = fifth_sch + '/' + fifth . name ;
124129 const sixth_schRe = '../' + fifth_schRe + '/' + fifth . name ;
125130 const sixth_helpRe = '../' + fifth_helpRe ;
131+ const sixth_mainRe = '../' + fifth_mainRe ;
126132 const sixth_runPath = fifth_runPath + '/' + third . name ;
127133
128134 fs . mkdirSync ( sixth_test + '/' , { recursive : true } )
@@ -133,7 +139,7 @@ async function generate(file) {
133139 await waitFor ( 50 )
134140 if ( sixth . hasOwnProperty ( 'item' ) == false ) {
135141 writeTest ( sixth , sixth_test , sixth_pageRe )
136- writePages ( sixth , sixth_page , sixth_schRe , sixth_helpRe )
142+ writePages ( sixth , sixth_page , sixth_schRe , sixth_helpRe , sixth_mainRe )
137143 writeJsonSchema ( sixth , sixth_sch )
138144 await waitFor ( 10 )
139145 }
@@ -153,6 +159,8 @@ async function generate(file) {
153159 const testPath = 'tests/scenarios' ;
154160 const testRelativePath = '../tests/scenarios' ;
155161 fs . mkdirSync ( testPath , { recursive : true } )
162+ // main pages path
163+ const mainpagesPath = './main.pages' ;
156164 // write pages dir
157165 const pagesPath = 'tests/pages' ;
158166 const pagesPathRelativePath = '../pages' ;
@@ -167,12 +175,12 @@ async function generate(file) {
167175
168176 writeRunner ( element , testRelativePath , runPath )
169177 writeTest ( element , testPath , pagesPathRelativePath )
170- writePages ( element , pagesPath , jsonSchemaRelativePath , helperPath )
178+ writePages ( element , pagesPath , jsonSchemaRelativePath , helperPath , mainpagesPath )
171179 writeJsonSchema ( element , jsonSchemaPath )
172180 await waitFor ( 10 )
173181 }
174182 } ) ;
175183 } )
176184}
177185
178- module . exports = generate
186+ export default generate
0 commit comments