11import path from "path" ;
2- import { clearStyle , run } from "./utils" ;
2+ import { clearStyle } from "./utils" ;
3+
4+ import { runCLI } from "@web3api/test-env-js" ;
35
46const HELP = `
57w3 build [options] [<web3api-manifest>]
@@ -17,83 +19,63 @@ describe("e2e tests for build command", () => {
1719 const projectRoot = path . resolve ( __dirname , "../project/" ) ;
1820
1921 test ( "Should show help text" , async ( ) => {
20- const errorHandler = jest . fn ( ) ;
21-
22- const { code, output } = await run (
23- "../../../bin/w3" ,
24- [ "build" , "--help" ] ,
25- projectRoot ,
26- errorHandler
27- ) ;
22+ const { exitCode : code , stdout : output , stderr : error } = await runCLI ( {
23+ args : [ "build" , "--help" ] ,
24+ cwd : projectRoot
25+ } , "../../../bin/w3" ) ;
2826
2927 expect ( code ) . toEqual ( 0 ) ;
30- expect ( errorHandler ) . not . toBeCalled ( ) ;
28+ expect ( error ) . toBe ( "" ) ;
3129 expect ( clearStyle ( output ) ) . toEqual ( HELP ) ;
3230 } ) ;
3331
3432 test ( "Should throw error for invalid params - outputDir" , async ( ) => {
35- const errorHandler = jest . fn ( ) ;
36-
37- const { code, output } = await run (
38- "../../../bin/w3" ,
39- [ "build" , "--output-dir" ] ,
40- projectRoot ,
41- errorHandler
42- ) ;
33+ const { exitCode : code , stdout : output , stderr : error } = await runCLI ( {
34+ args : [ "build" , "--output-dir" ] ,
35+ cwd : projectRoot
36+ } , "../../../bin/w3" ) ;
4337
4438 expect ( code ) . toEqual ( 0 ) ;
45- expect ( errorHandler ) . not . toBeCalled ( ) ;
39+ expect ( error ) . toBe ( "" ) ;
4640 expect ( clearStyle ( output ) )
4741 . toEqual ( `--output-dir option missing <path> argument
4842${ HELP } `) ;
4943 } ) ;
5044
5145 test ( "Should throw error for invalid params - testEns" , async ( ) => {
52- const errorHandler = jest . fn ( ) ;
53-
54- const { code, output } = await run (
55- "../../../bin/w3" ,
56- [ "build" , "--test-ens" ] ,
57- projectRoot ,
58- errorHandler
59- ) ;
46+ const { exitCode : code , stdout : output , stderr : error } = await runCLI ( {
47+ args : [ "build" , "--test-ens" ] ,
48+ cwd : projectRoot
49+ } , "../../../bin/w3" ) ;
6050
6151 expect ( code ) . toEqual ( 0 ) ;
62- expect ( errorHandler ) . not . toBeCalled ( ) ;
52+ expect ( error ) . toBe ( "" ) ;
6353 expect ( clearStyle ( output ) )
6454 . toEqual ( `--test-ens option missing <[address,]domain> argument
6555${ HELP } `) ;
6656 } ) ;
6757
6858 test ( "Should throw error for invalid params - ipfs" , async ( ) => {
69- const errorHandler = jest . fn ( ) ;
70-
71- const { code, output } = await run (
72- "../../../bin/w3" ,
73- [ "build" , "--test-ens" , "test.eth" ] ,
74- projectRoot ,
75- errorHandler
76- ) ;
59+ const { exitCode : code , stdout : output , stderr : error } = await runCLI ( {
60+ args : [ "build" , "--test-ens" , "test.eth" ] ,
61+ cwd : projectRoot
62+ } , "../../../bin/w3" ) ;
7763
7864 expect ( code ) . toEqual ( 0 ) ;
79- expect ( errorHandler ) . not . toBeCalled ( ) ;
65+ expect ( error ) . toBe ( "" ) ;
8066 expect ( clearStyle ( output ) )
8167 . toEqual ( `--test-ens option requires the --ipfs [<node>] option
8268${ HELP } `) ;
8369 } ) ;
8470
8571 test ( "Should throw error for invalid web3api - invalid route" , async ( ) => {
86- const errorHandler = jest . fn ( ) ;
87-
88- const { code, output } = await run (
89- "../../../bin/w3" ,
90- [ "build" , "invalid-web3api-1.yaml" ] ,
91- projectRoot ,
92- errorHandler
93- ) ;
72+ const { exitCode : code , stdout : output , stderr : error } = await runCLI ( {
73+ args : [ "build" , "invalid-web3api-1.yaml" ] ,
74+ cwd : projectRoot
75+ } , "../../../bin/w3" ) ;
9476
9577 expect ( code ) . toEqual ( 1 ) ;
96- expect ( errorHandler ) . not . toBeCalled ( ) ;
78+ expect ( error ) . toBe ( "" ) ;
9779 expect ( clearStyle ( output ) ) . toContain ( `- Compile Web3API
9880- Load web3api from invalid-web3api-1.yaml
9981✔ Load web3api from invalid-web3api-1.yaml
@@ -102,34 +84,26 @@ ${HELP}`);
10284 } ) ;
10385
10486 test ( "Should throw error for invalid web3api - invalid field" , async ( ) => {
105- const errorHandler = jest . fn ( ) ;
106-
107- const { code, output } = await run (
108- "../../../bin/w3" ,
109- [ "build" , "invalid-web3api-2.yaml" ] ,
110- projectRoot ,
111- errorHandler
112- ) ;
87+ const { exitCode : code , stdout : output , stderr : error } = await runCLI ( {
88+ args : [ "build" , "invalid-web3api-2.yaml" ] ,
89+ cwd : projectRoot
90+ } , "../../../bin/w3" ) ;
11391
11492 expect ( code ) . toEqual ( 1 ) ;
115- expect ( errorHandler ) . not . toBeCalled ( ) ;
93+ expect ( error ) . toBe ( "" ) ;
11694 expect ( clearStyle ( output ) ) . toContain ( `- Compile Web3API
11795- Load web3api from invalid-web3api-2.yaml
11896✖ Failed to load web3api from invalid-web3api-2.yaml: Field wrong_mutation is not accepted in the schema. Please check the accepted fields here:` ) ;
11997 } ) ;
12098
12199 test ( "Successfully build the project" , async ( ) => {
122- const errorHandler = jest . fn ( ) ;
123-
124- const { code, output } = await run (
125- "../../../bin/w3" ,
126- [ "build" ] ,
127- projectRoot ,
128- errorHandler
129- ) ;
100+ const { exitCode : code , stdout : output , stderr : error } = await runCLI ( {
101+ args : [ "build" ] ,
102+ cwd : projectRoot
103+ } , "../../../bin/w3" ) ;
130104
131105 expect ( code ) . toEqual ( 0 ) ;
132- expect ( errorHandler ) . not . toBeCalled ( ) ;
106+ expect ( error ) . toBe ( "" ) ;
133107 expect ( clearStyle ( output ) ) . toEqual ( `- Compile Web3API
134108- Load web3api from web3api.yaml
135109✔ Load web3api from web3api.yaml
0 commit comments