|
| 1 | +import { join } from 'path'; |
| 2 | +import { writeFileSync } from 'fs'; |
| 3 | + |
| 4 | +import { removeSync } from 'fs-extra'; |
| 5 | + |
1 | 6 | import pack from './utils/pack';
|
2 | 7 |
|
| 8 | +const target = join(__dirname, 'fixtures', 'lint-dirty-modules-only-entry.js'); |
| 9 | + |
3 | 10 | describe('lint dirty modules only', () => {
|
| 11 | + let watch; |
| 12 | + afterEach(() => { |
| 13 | + if (watch) { |
| 14 | + watch.close(); |
| 15 | + } |
| 16 | + removeSync(target); |
| 17 | + }); |
| 18 | + |
4 | 19 | it('skips linting on initial run', (done) => {
|
5 |
| - const compiler = pack('error', { lintDirtyModulesOnly: true }); |
| 20 | + writeFileSync(target, 'const foo = false\n'); |
| 21 | + |
| 22 | + let next = firstPass; |
| 23 | + const compiler = pack('lint-dirty-modules-only', { |
| 24 | + lintDirtyModulesOnly: true, |
| 25 | + }); |
| 26 | + watch = compiler.watch({}, (err, stats) => next(err, stats)); |
6 | 27 |
|
7 |
| - compiler.run((err, stats) => { |
| 28 | + function firstPass(err, stats) { |
8 | 29 | expect(err).toBeNull();
|
9 | 30 | expect(stats.hasWarnings()).toBe(false);
|
10 | 31 | expect(stats.hasErrors()).toBe(false);
|
| 32 | + |
| 33 | + next = secondPass; |
| 34 | + |
| 35 | + writeFileSync(target, 'const bar = false;\n'); |
| 36 | + } |
| 37 | + |
| 38 | + function secondPass(err, stats) { |
| 39 | + expect(err).toBeNull(); |
| 40 | + expect(stats.hasWarnings()).toBe(false); |
| 41 | + expect(stats.hasErrors()).toBe(true); |
| 42 | + const { errors } = stats.compilation; |
| 43 | + expect(errors.length).toBe(1); |
| 44 | + const [{ message }] = errors; |
| 45 | + expect(message).toEqual(expect.stringMatching('no-unused-vars')); |
11 | 46 | done();
|
12 |
| - }); |
| 47 | + } |
13 | 48 | });
|
14 | 49 | });
|
0 commit comments