|
2 | 2 | // search around the file system for stuff |
3 | 3 |
|
4 | 4 | const eslint = jest.requireActual('eslint'); |
5 | | -const { CLIEngine } = eslint; |
| 5 | +const { ESLint } = eslint; |
6 | 6 |
|
7 | | -const mockGetConfigForFileSpy = jest.fn(mockGetConfigForFile); |
8 | | -mockGetConfigForFileSpy.overrides = {}; |
9 | | -const mockExecuteOnTextSpy = jest.fn(mockExecuteOnText); |
| 7 | +const mockCalculateConfigForFileSpy = jest.fn(mockCalculateConfigForFile); |
| 8 | +mockCalculateConfigForFileSpy.overrides = {}; |
| 9 | +const mockLintTextSpy = jest.fn(mockLintText); |
10 | 10 |
|
11 | 11 | module.exports = Object.assign(eslint, { |
12 | | - CLIEngine: jest.fn(MockCLIEngine), |
| 12 | + ESLint: jest.fn(MockESLint), |
13 | 13 | mock: { |
14 | | - getConfigForFile: mockGetConfigForFileSpy, |
15 | | - executeOnText: mockExecuteOnTextSpy |
| 14 | + calculateConfigForFile: mockCalculateConfigForFileSpy, |
| 15 | + lintText: mockLintTextSpy |
16 | 16 | } |
17 | 17 | }); |
18 | 18 |
|
19 | | -function MockCLIEngine(...args) { |
| 19 | +function MockESLint(...args) { |
20 | 20 | global.__PRETTIER_ESLINT_TEST_STATE__.eslintPath = __filename; |
21 | | - const cliEngine = new CLIEngine(...args); |
22 | | - cliEngine.getConfigForFile = mockGetConfigForFileSpy; |
23 | | - cliEngine._originalExecuteOnText = cliEngine.executeOnText; |
24 | | - cliEngine.executeOnText = mockExecuteOnTextSpy; |
25 | | - return cliEngine; |
| 21 | + const eslintInstance = new ESLint(...args); |
| 22 | + eslintInstance.calculateConfigForFile = mockCalculateConfigForFileSpy; |
| 23 | + eslintInstance._originalLintText = eslintInstance.lintText; |
| 24 | + eslintInstance.lintText = mockLintTextSpy; |
| 25 | + return eslintInstance; |
26 | 26 | } |
27 | 27 |
|
28 | | -MockCLIEngine.prototype = Object.create(CLIEngine.prototype); |
| 28 | +MockESLint.prototype = Object.create(ESLint.prototype); |
29 | 29 |
|
30 | 30 | // eslint-disable-next-line complexity |
31 | | -function mockGetConfigForFile(filePath) { |
32 | | - if (mockGetConfigForFileSpy.throwError) { |
33 | | - throw mockGetConfigForFileSpy.throwError; |
| 31 | +function mockCalculateConfigForFile(filePath) { |
| 32 | + if (mockCalculateConfigForFileSpy.throwError) { |
| 33 | + throw mockCalculateConfigForFileSpy.throwError; |
34 | 34 | } |
35 | 35 | if (!filePath) { |
36 | 36 | return { |
@@ -71,10 +71,10 @@ function mockGetConfigForFile(filePath) { |
71 | 71 | } |
72 | 72 | } |
73 | 73 |
|
74 | | -function mockExecuteOnText(...args) { |
75 | | - /* eslint babel/no-invalid-this:0 */ |
76 | | - if (mockExecuteOnTextSpy.throwError) { |
77 | | - throw mockExecuteOnTextSpy.throwError; |
| 74 | +function mockLintText(...args) { |
| 75 | + /* eslint no-invalid-this:0 */ |
| 76 | + if (mockLintTextSpy.throwError) { |
| 77 | + throw mockLintTextSpy.throwError; |
78 | 78 | } |
79 | | - return this._originalExecuteOnText(...args); |
| 79 | + return this._originalLintText(...args); |
80 | 80 | } |
0 commit comments