|
1 | 1 | import { LogLevels } from 'bs-logger' |
2 | | -import { readFileSync } from 'fs' |
| 2 | +import { readFileSync, renameSync } from 'fs' |
3 | 3 | import { removeSync } from 'fs-extra' |
4 | 4 | import { join } from 'path' |
5 | 5 |
|
@@ -174,6 +174,54 @@ describe('Language service', () => { |
174 | 174 | removeSync(cacheDir) |
175 | 175 | }) |
176 | 176 |
|
| 177 | + it(`should not report diagnostics for test file which doesn't exist when compiling import module file`, async () => { |
| 178 | + const testFileName = require.resolve('../__mocks__/thing.spec.ts') |
| 179 | + const testFileContent = readFileSync(testFileName, 'utf-8') |
| 180 | + const cacheDir = join(process.cwd(), 'tmp') |
| 181 | + /** |
| 182 | + * Run the 1st compilation with Promise resolve setTimeout to stimulate 2 different test runs to test cached |
| 183 | + * resolved modules |
| 184 | + */ |
| 185 | + async function firstCompile() { |
| 186 | + return new Promise((resolve) => { |
| 187 | + const compiler1 = makeCompiler({ |
| 188 | + jestConfig: { |
| 189 | + cache: true, |
| 190 | + cacheDirectory: cacheDir, |
| 191 | + }, |
| 192 | + tsJestConfig: baseTsJestConfig, |
| 193 | + }) |
| 194 | + |
| 195 | + logTarget.clear() |
| 196 | + compiler1.compile(testFileContent, testFileName) |
| 197 | + |
| 198 | + // probably 300ms is enough to stimulate 2 separated runs after each other |
| 199 | + setTimeout(() => resolve(), 300) |
| 200 | + }) |
| 201 | + } |
| 202 | + |
| 203 | + await firstCompile() |
| 204 | + |
| 205 | + const newTestFileName = testFileName.replace('thing', 'thing2') |
| 206 | + renameSync(testFileName, newTestFileName) |
| 207 | + |
| 208 | + const compiler2 = makeCompiler({ |
| 209 | + jestConfig: { |
| 210 | + cache: true, |
| 211 | + cacheDirectory: cacheDir, |
| 212 | + }, |
| 213 | + tsJestConfig: baseTsJestConfig, |
| 214 | + }) |
| 215 | + logTarget.clear() |
| 216 | + |
| 217 | + compiler2.compile(importedFileContent, importedFileName) |
| 218 | + |
| 219 | + expect(logTarget.filteredLines(LogLevels.debug, Infinity)).toMatchSnapshot() |
| 220 | + |
| 221 | + renameSync(newTestFileName, testFileName) |
| 222 | + removeSync(cacheDir) |
| 223 | + }) |
| 224 | + |
177 | 225 | it(`should only report diagnostics for imported modules but not test files without cache`, () => { |
178 | 226 | const testFileName = require.resolve('../__mocks__/thing1.spec.ts') |
179 | 227 | const testFileContent = readFileSync(testFileName, 'utf-8') |
|
0 commit comments