@@ -12,34 +12,111 @@ const cwd = name => path.join(process.cwd(), 'test', 'fixtures', name);
1212const run = async ( fixtureName , options ) => await exec ( `${ cliPath } modules download ${ options } ` , { cwd : cwd ( fixtureName ) , env : process . env } ) ;
1313
1414describe ( 'Successful download' , ( ) => {
15- test ( 'download test module' , async ( ) => {
15+
16+ test ( 'download test module in the correct version' , async ( ) => {
17+ const pathToModuleJson = `${ cwd ( 'deploy/modules_test' ) } /modules/tests/template-values.json` ;
18+ const pathToDirectory = `${ cwd ( 'deploy/modules_test' ) } /modules` ;
19+
20+ const { stdout } = await run ( 'deploy/modules_test' , 'tests' ) ;
21+ expect ( stdout ) . toContain ( 'Downloading [email protected] ' ) ; 22+ expect ( fs . existsSync ( pathToModuleJson ) ) . toBeTruthy ( ) ;
23+
24+ const moduleJson = JSON . parse ( fs . readFileSync ( pathToModuleJson , 'utf8' ) ) ;
25+ expect ( moduleJson . version ) . toBe ( '0.0.3' ) ;
26+
27+ fs . rm ( pathToDirectory , { recursive : true } , ( err ) => {
28+ if ( err ) {
29+ console . error ( err . message ) ;
30+ return ;
31+ }
32+ } ) ;
33+ } ) ;
34+
35+ test ( 'download test module in a specific version' , async ( ) => {
1636 const pathToModuleJson = `${ cwd ( 'deploy/modules_test' ) } /modules/tests/template-values.json` ;
1737 const pathToDirectory = `${ cwd ( 'deploy/modules_test' ) } /modules` ;
1838
19- const { stdout, stderr } = await run ( 'deploy/modules_test' , 'tests' ) ;
20- expect ( stdout ) . toMatch ( 'Downloading files ' ) ;
39+ const { stdout } = await run ( 'deploy/modules_test' , 'tests@1.0.0 ' ) ;
40+ expect ( stdout ) . toContain ( 'Downloading [email protected] ' ) ; 2141 expect ( fs . existsSync ( pathToModuleJson ) ) . toBeTruthy ( ) ;
2242
43+ const moduleJson = JSON . parse ( fs . readFileSync ( pathToModuleJson , 'utf8' ) ) ;
44+ expect ( moduleJson . version ) . toBe ( '1.0.0' ) ;
45+
2346 fs . rm ( pathToDirectory , { recursive : true } , ( err ) => {
2447 if ( err ) {
25- console . error ( err . message ) ;
26- return ;
48+ console . error ( err . message ) ;
49+ return ;
2750 }
2851 } ) ;
2952 } ) ;
53+
54+ test ( 'download the latest test module if no app/pos-modules.lock.json' , async ( ) => {
55+ const pathToModuleJson = `${ cwd ( 'deploy/empty' ) } /modules/tests/template-values.json` ;
56+ const pathToDirectory = `${ cwd ( 'deploy/empty' ) } /modules` ;
57+
58+ const { stdout, stderr } = await run ( 'deploy/empty' , 'tests' ) ;
59+ expect ( stdout ) . toContain ( 'Downloading tests...' ) ;
60+ expect ( stderr ) . toContain ( 'Warning: Can\'t find app/pos-modules.lock.json' ) ;
61+ expect ( fs . existsSync ( pathToModuleJson ) ) . toBeTruthy ( ) ;
62+
63+ fs . rm ( pathToDirectory , { recursive : true } , ( err ) => {
64+ if ( err ) {
65+ console . error ( err . message ) ;
66+ return ;
67+ }
68+ } ) ;
69+ } ) ;
70+
71+
72+ test ( 'download user module with dependencies' , async ( ) => {
73+ const pathToUserModuleJson = `${ cwd ( 'deploy/modules_user' ) } /modules/user/template-values.json` ;
74+ const pathToCoreModuleJson = `${ cwd ( 'deploy/modules_user' ) } /modules/core/template-values.json` ;
75+ const pathToDirectory = `${ cwd ( 'deploy/modules_user' ) } /modules` ;
76+
77+ const { stdout : stdout1 } = await run ( 'deploy/modules_user' , 'user' ) ;
78+ expect ( stdout1 ) . toContain ( 'Downloading [email protected] ' ) ; 79+ expect ( fs . existsSync ( pathToUserModuleJson ) ) . toBeTruthy ( ) ;
80+ expect ( stdout1 ) . toContain ( 'Downloading [email protected] ' ) ; 81+ expect ( fs . existsSync ( pathToCoreModuleJson ) ) . toBeTruthy ( ) ;
82+
83+ const userModuleJson = JSON . parse ( fs . readFileSync ( pathToUserModuleJson , 'utf8' ) ) ;
84+ expect ( userModuleJson . version ) . toBe ( '3.0.8' ) ;
85+ const coreModuleJson = JSON . parse ( fs . readFileSync ( pathToCoreModuleJson , 'utf8' ) ) ;
86+ expect ( coreModuleJson . version ) . toBe ( '1.5.5' ) ;
87+
88+ // do not download dependency again
89+
90+ const { stdout : stdout2 } = await run ( 'deploy/modules_user' , 'user' ) ;
91+ expect ( stdout2 ) . toContain ( 'Downloading [email protected] ' ) ; 92+ expect ( stdout2 ) . not . toContain ( 'Downloading [email protected] ' ) ; 93+
94+ // download again if forced
95+
96+ const { stdout : stdout3 } = await run ( 'deploy/modules_user' , 'user --force-dependencies' ) ;
97+ expect ( stdout3 ) . toContain ( 'Downloading [email protected] ' ) ; 98+ expect ( stdout3 ) . toContain ( 'Downloading [email protected] ' ) ; 99+
100+ fs . rm ( pathToDirectory , { recursive : true } , ( err ) => {
101+ if ( err ) {
102+ console . error ( err . message ) ;
103+ return ;
104+ }
105+ } ) ;
106+ } , 20000 ) ;
30107} ) ;
31108
32109describe ( 'Failed download' , ( ) => {
33110 test ( 'Module not found - non-existing module' , async ( ) => {
34- const { stdout , stderr } = await run ( 'deploy/modules_test' , 'moduleNotFound' ) ;
35- expect ( stderr ) . toMatch ( 'Module not found') ;
111+ const { stderr } = await run ( 'deploy/modules_test' , 'moduleNotFound' ) ;
112+ expect ( stderr ) . toContain ( 'moduleNotFound: 404 not found') ;
36113 } ) ;
37114 test ( 'Module not found - no name for module' , async ( ) => {
38- const { stdout , stderr } = await run ( 'deploy/modules_test' , '' ) ;
115+ const { stderr } = await run ( 'deploy/modules_test' , '' ) ;
39116 expect ( stderr ) . toMatch ( "error: missing required argument 'module'" ) ;
40117 } ) ;
41118 test ( 'Unescaped characters in request path' , async ( ) => {
42- const { stdout , stderr } = await run ( 'deploy/modules_test' , 'ąę' ) ;
119+ const { stderr } = await run ( 'deploy/modules_test' , 'ąę' ) ;
43120 expect ( stderr ) . toMatch ( '[ERR_UNESCAPED_CHARACTERS]: Request path contains unescaped characters' ) ;
44121 } ) ;
45122} ) ;
0 commit comments