11import { solidarity } from '../../src'
22import getSolidaritySettings from '../../src/extensions/functions/getSolidaritySettings'
33
4- const context = require ( 'gluegun/toolbox ' )
4+ const context = require ( 'mockContext ' )
55
6- describe ( 'getSolidaritySettings' , ( ) => {
6+ describe ( 'basic getSolidaritySettings' , ( ) => {
77 describe ( 'w/ success' , ( ) => {
88 test ( 'getSolidaritySettings exists' , ( ) => expect ( getSolidaritySettings ) . toMatchSnapshot ( ) )
99
10- test ( 'getSolidaritySettings succeeds' , async ( ) => {
10+ test ( 'getSolidaritySettings succeeds' , ( ) => {
1111 const resultSettings = getSolidaritySettings ( context )
1212 // we got an object with requirements defined
1313 expect ( resultSettings ) . toMatchObject ( { requirements : { } } )
1414 } )
1515
16- test ( 'getSolidaritySettings succeeds' , async ( ) => {
16+ test ( 'getSolidaritySettings succeeds' , ( ) => {
1717 process . chdir ( '__tests__/sandbox/solidarity_json' )
1818 const resultSettings = getSolidaritySettings ( context )
1919 // we got an object with requirements defined
@@ -22,19 +22,98 @@ describe('getSolidaritySettings', () => {
2222 } )
2323 } )
2424
25- test ( 'getSolidaritySettings can fail' , async ( ) => {
25+ describe ( 'w/ failure' , ( ) => {
26+ test ( 'getSolidaritySettings can fail' , ( ) => {
27+ expect ( ( ) => {
28+ process . chdir ( '__tests__' )
29+ const resultSettings = getSolidaritySettings ( context )
30+ } ) . toThrow ( )
31+ process . chdir ( '../' )
32+ } )
33+
34+ test ( 'getSolidaritySettings can warn with missing requirements' , ( ) => {
35+ expect ( ( ) => {
36+ process . chdir ( '__tests__/sandbox/solidarity_broken' )
37+ const resultSettings = getSolidaritySettings ( context )
38+ } ) . toThrowError ( 'ERROR: Found, but no requirements key. Please validate your solidarity file' )
39+ process . chdir ( '../../../' )
40+ } )
41+ }
42+ } )
43+
44+ describe ( 'parameterized getSolidaritySettings' , ( ) => {
45+
46+ test ( 'custom path with -f' , ( ) => {
47+ context . parameters . options = { f : '__tests__/sandbox/solidarity_json' }
48+ const resultSettings = getSolidaritySettings ( context )
49+ // we got an object with requirements defined
50+ expect ( resultSettings ) . toMatchObject ( { requirements : { } } )
51+ context . parameters . options = { }
52+ } )
53+
54+ test ( 'custom path with --solidarityFile' , ( ) => {
55+ context . parameters . options = { solidarityFile : '__tests__/sandbox/solidarity_json' }
56+ const resultSettings = getSolidaritySettings ( context )
57+ // we got an object with requirements defined
58+ expect ( resultSettings ) . toMatchObject ( { requirements : { } } )
59+ context . parameters . options = { }
60+ } )
61+
62+ test ( 'failing path message' , ( ) => {
63+ // test longhand
64+ context . parameters . options = { solidarityFile : '__tests__/fake' }
2665 expect ( ( ) => {
27- process . chdir ( '__tests__' )
2866 const resultSettings = getSolidaritySettings ( context )
29- } ) . toThrow ( )
30- process . chdir ( '../' )
67+ } ) . toThrowError ( 'ERROR: There is no solidarity file at the given path' )
68+ // test shorthand
69+ context . parameters . options = { f : '__tests__/fake' }
70+ expect ( ( ) => {
71+ const resultSettings = getSolidaritySettings ( context )
72+ } ) . toThrowError ( 'ERROR: There is no solidarity file at the given path' )
73+ context . parameters . options = { }
3174 } )
3275
33- test ( 'getSolidaritySettings can warn with missing requirements' , async ( ) => {
34- expect ( ( ) => {
35- process . chdir ( '__tests__/sandbox/solidarity_broken' )
76+ describe ( 'custom module tests' , ( ) => {
77+ beforeAll ( ( ) => {
78+ process . chdir ( '__tests__/sandbox/fake_project' )
79+ } )
80+
81+ test ( 'can find solidarity file in module with flag -m' , ( ) => {
82+ context . parameters . options = { m : 'mock_module' }
83+ const resultSettings = getSolidaritySettings ( context )
84+ // we got an object with requirements defined
85+ expect ( resultSettings ) . toMatchObject ( { requirements : { } } )
86+ context . parameters . options = { }
87+ } )
88+
89+ test ( 'can find solidarity file in module with flag --module' , ( ) => {
90+ context . parameters . options = { module : 'mock_module' }
3691 const resultSettings = getSolidaritySettings ( context )
37- } ) . toThrowError ( 'ERROR: Found, but no requirements key. Please validate your solidarity file' )
38- process . chdir ( '../../../' )
92+ // we got an object with requirements defined
93+ expect ( resultSettings ) . toMatchObject ( { requirements : { } } )
94+ context . parameters . options = { }
95+ } )
96+
97+ test ( 'can find solidarity JSON file in module with flag --module' , ( ) => {
98+ context . parameters . options = { module : 'mock_second_module' }
99+ const resultSettings = getSolidaritySettings ( context )
100+ // we got an object with requirements defined
101+ expect ( resultSettings ) . toMatchObject ( { requirements : { } } )
102+ context . parameters . options = { }
103+ } )
104+
105+ test ( 'errors if no solidarity file in module' , ( ) => {
106+ context . parameters . options = { module : 'nope' }
107+ expect ( ( ) => {
108+ const resultSettings = getSolidaritySettings ( context )
109+ } ) . toThrowError ( 'ERROR: There is no solidarity file found with the given module' )
110+ context . parameters . options = { }
111+ } )
112+
113+ afterAll ( ( ) => {
114+ process . chdir ( '../../../' )
115+ } )
116+
39117 } )
118+
40119} )
0 commit comments