-
-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: use hook `afterCompile` instead of `afterEmit` * fix: use hook `watchRun` instead of `emit` for lintDirtyModulesOnly * test: refactor
- Loading branch information
1 parent
80f7c4f
commit 792fe19
Showing
4 changed files
with
63 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import LintDirtyModulesPlugin from '../src/LintDirtyModulesPlugin'; | ||
import linter from '../src/linter'; | ||
|
||
jest.mock('../src/linter'); | ||
|
||
describe('lint dirty modules only', () => { | ||
let plugin; | ||
let callback; | ||
|
||
beforeAll(() => { | ||
callback = jest.fn(); | ||
|
||
plugin = new LintDirtyModulesPlugin(null, { files: ['**\\*.s?(c|a)ss'] }); | ||
}); | ||
|
||
beforeEach(() => { | ||
linter.mockRestore(); | ||
callback.mockRestore(); | ||
}); | ||
|
||
it('skips linting on initial run', () => { | ||
expect(plugin.isFirstRun).toBe(true); | ||
expect(callback).not.toBeCalled(); | ||
|
||
plugin.apply({}, callback); | ||
|
||
expect(plugin.isFirstRun).toBe(false); | ||
expect(callback).toBeCalledTimes(1); | ||
}); | ||
|
||
it('linting on change file', () => { | ||
const fileTimestamps = new Map([ | ||
['foo/changed.scss', 1], | ||
['bar\\changed.scss', 1], | ||
['new-file.scss'], | ||
]); | ||
|
||
plugin.isFirstRun = false; | ||
plugin.prevTimestamps = new Map([ | ||
['foo/changed.scss', 2], | ||
['bar\\changed.scss', 2], | ||
]); | ||
plugin.apply({ fileTimestamps }, callback); | ||
|
||
expect(linter).toBeCalledTimes(1); | ||
expect(callback).not.toBeCalled(); | ||
}); | ||
|
||
it('not linter if files are not changed', () => { | ||
const fileTimestamps = new Map([['not-changed.scss', 1]]); | ||
|
||
plugin.isFirstRun = false; | ||
plugin.prevTimestamps = fileTimestamps; | ||
plugin.apply({ fileTimestamps }, callback); | ||
|
||
expect(linter).not.toBeCalled(); | ||
expect(callback).toBeCalledTimes(1); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters