|
1 | 1 | //@flow |
2 | | -import{run}from'../runTests'; |
| 2 | +importfsfrom'fs'; |
| 3 | + |
| 4 | +import{run,writeFlowConfig,TEST_DIR}from'../runTests'; |
3 | 5 | import{path}from'../../lib/node'; |
4 | 6 |
|
5 | 7 | describe('run-tests (command)',()=>{ |
@@ -31,4 +33,167 @@ describe('run-tests (command)', () => { |
31 | 33 | expect(lastErrorMsg).toContain(expectedError); |
32 | 34 | }); |
33 | 35 | }); |
| 36 | + |
| 37 | +describe('writeFlowConfig',()=>{ |
| 38 | +constfixtureBasePath=path.join( |
| 39 | +process.cwd(), |
| 40 | +'src/commands/__tests__/__runTests-fixtures__', |
| 41 | +); |
| 42 | +consttestDir=path.join(TEST_DIR,'unit-test'); |
| 43 | +constflowConfigFile=path.join(testDir,'.flowconfig'); |
| 44 | + |
| 45 | +beforeAll(()=>{ |
| 46 | +fs.mkdirSync(testDir,{recursive:true}); |
| 47 | +}); |
| 48 | + |
| 49 | +afterAll(()=>{ |
| 50 | +fs.rmdirSync(testDir,{recursive:true}); |
| 51 | +}); |
| 52 | + |
| 53 | +it('writes the file correctly',async()=>{ |
| 54 | +awaitwriteFlowConfig( |
| 55 | +fixtureBasePath, |
| 56 | +testDir, |
| 57 | +path.join(fixtureBasePath,'definitions/npm/def/'), |
| 58 | +'0.181.0', |
| 59 | +[], |
| 60 | +); |
| 61 | + |
| 62 | +constflowConfigSplit=fs |
| 63 | +.readFileSync(flowConfigFile,'utf-8') |
| 64 | +.split('\n'); |
| 65 | + |
| 66 | +constmatches=[ |
| 67 | +'[libs]', |
| 68 | +'def', |
| 69 | +/.*cli\/src\/commands\/__tests__\/__util__\/tdd_framework\.js$/, |
| 70 | +'', |
| 71 | +'[options]', |
| 72 | +'include_warnings=true', |
| 73 | +'server.max_workers=0', |
| 74 | +'sharedmemory.heap_size=3221225472', |
| 75 | +'', |
| 76 | +'', |
| 77 | +'[ignore]', |
| 78 | +/.*\/cli\/node_modules$/, |
| 79 | +'', |
| 80 | +'[lints]', |
| 81 | +'implicit-inexact-object=error', |
| 82 | +]; |
| 83 | + |
| 84 | +matches.forEach((match,i)=>{ |
| 85 | +expect(flowConfigSplit[i]).toMatch(match); |
| 86 | +}); |
| 87 | +}); |
| 88 | + |
| 89 | +it('writes flow suppression if flow version is less than 0.125.0',async()=>{ |
| 90 | +awaitwriteFlowConfig( |
| 91 | +fixtureBasePath, |
| 92 | +testDir, |
| 93 | +path.join(fixtureBasePath,'definitions/npm/def/'), |
| 94 | +'0.124.0', |
| 95 | +[], |
| 96 | +); |
| 97 | + |
| 98 | +constflowConfigSplit=fs |
| 99 | +.readFileSync(flowConfigFile,'utf-8') |
| 100 | +.split('\n'); |
| 101 | + |
| 102 | +constmatches=[ |
| 103 | +'[libs]', |
| 104 | +'def', |
| 105 | +/.*cli\/src\/commands\/__tests__\/__util__\/tdd_framework\.js$/, |
| 106 | +'', |
| 107 | +'[options]', |
| 108 | +'include_warnings=true', |
| 109 | +'server.max_workers=0', |
| 110 | +'sharedmemory.heap_size=3221225472', |
| 111 | +'suppress_comment=\\\\(.\\\\|\\n\\\\)*\\\\$FlowExpectedError', |
| 112 | +'', |
| 113 | +'[ignore]', |
| 114 | +/.*\/cli\/node_modules$/, |
| 115 | +'', |
| 116 | +'[lints]', |
| 117 | +'implicit-inexact-object=error', |
| 118 | +]; |
| 119 | + |
| 120 | +matches.forEach((match,i)=>{ |
| 121 | +expect(flowConfigSplit[i]).toMatch(match); |
| 122 | +}); |
| 123 | +}); |
| 124 | + |
| 125 | +it('does not have inexplicit lint when less than flow version less than 0.104.0',async()=>{ |
| 126 | +awaitwriteFlowConfig( |
| 127 | +fixtureBasePath, |
| 128 | +testDir, |
| 129 | +path.join(fixtureBasePath,'definitions/npm/def/'), |
| 130 | +'0.103.0', |
| 131 | +[], |
| 132 | +); |
| 133 | + |
| 134 | +constflowConfigSplit=fs |
| 135 | +.readFileSync(flowConfigFile,'utf-8') |
| 136 | +.split('\n'); |
| 137 | + |
| 138 | +constmatches=[ |
| 139 | +'[libs]', |
| 140 | +'def', |
| 141 | +/.*cli\/src\/commands\/__tests__\/__util__\/tdd_framework\.js$/, |
| 142 | +'', |
| 143 | +'[options]', |
| 144 | +'include_warnings=true', |
| 145 | +'server.max_workers=0', |
| 146 | +'sharedmemory.heap_size=3221225472', |
| 147 | +'suppress_comment=\\\\(.\\\\|\\n\\\\)*\\\\$FlowExpectedError', |
| 148 | +'', |
| 149 | +'[ignore]', |
| 150 | +/.*\/cli\/node_modules$/, |
| 151 | +'', |
| 152 | +'[lints]', |
| 153 | +'', |
| 154 | +]; |
| 155 | + |
| 156 | +matches.forEach((match,i)=>{ |
| 157 | +expect(flowConfigSplit[i]).toMatch(match); |
| 158 | +}); |
| 159 | +}); |
| 160 | + |
| 161 | +it('writes the dependency definitions correctly',async()=>{ |
| 162 | +awaitwriteFlowConfig( |
| 163 | +fixtureBasePath, |
| 164 | +testDir, |
| 165 | +path.join(fixtureBasePath,'definitions/npm/def/'), |
| 166 | +'0.183.0', |
| 167 | +['dep-1','dep-2'], |
| 168 | +); |
| 169 | + |
| 170 | +constflowConfigSplit=fs |
| 171 | +.readFileSync(flowConfigFile,'utf-8') |
| 172 | +.split('\n'); |
| 173 | + |
| 174 | +constmatches=[ |
| 175 | +'[libs]', |
| 176 | +'dep-1', |
| 177 | +'dep-2', |
| 178 | +'def', |
| 179 | +/.*cli\/src\/commands\/__tests__\/__util__\/tdd_framework\.js$/, |
| 180 | +'', |
| 181 | +'[options]', |
| 182 | +'include_warnings=true', |
| 183 | +'server.max_workers=0', |
| 184 | +'sharedmemory.heap_size=3221225472', |
| 185 | +'', |
| 186 | +'', |
| 187 | +'[ignore]', |
| 188 | +/.*\/cli\/node_modules$/, |
| 189 | +'', |
| 190 | +'[lints]', |
| 191 | +'', |
| 192 | +]; |
| 193 | + |
| 194 | +matches.forEach((match,i)=>{ |
| 195 | +expect(flowConfigSplit[i]).toMatch(match); |
| 196 | +}); |
| 197 | +}); |
| 198 | +}); |
34 | 199 | }); |