|
2 | 2 | // search around the file system for stuff |
3 | 3 |
|
4 | 4 | consteslint=jest.requireActual('eslint'); |
5 | | -const{CLIEngine}=eslint; |
| 5 | +const{ESLint}=eslint; |
6 | 6 |
|
7 | | -constmockGetConfigForFileSpy=jest.fn(mockGetConfigForFile); |
8 | | -mockGetConfigForFileSpy.overrides={}; |
9 | | -constmockExecuteOnTextSpy=jest.fn(mockExecuteOnText); |
| 7 | +constmockCalculateConfigForFileSpy=jest.fn(mockCalculateConfigForFile); |
| 8 | +mockCalculateConfigForFileSpy.overrides={}; |
| 9 | +constmockLintTextSpy=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 | | -functionMockCLIEngine(...args){ |
| 19 | +functionMockESLint(...args){ |
20 | 20 | global.__PRETTIER_ESLINT_TEST_STATE__.eslintPath=__filename; |
21 | | -constcliEngine=newCLIEngine(...args); |
22 | | -cliEngine.getConfigForFile=mockGetConfigForFileSpy; |
23 | | -cliEngine._originalExecuteOnText=cliEngine.executeOnText; |
24 | | -cliEngine.executeOnText=mockExecuteOnTextSpy; |
25 | | -returncliEngine; |
| 21 | +consteslintInstance=newESLint(...args); |
| 22 | +eslintInstance.calculateConfigForFile=mockCalculateConfigForFileSpy; |
| 23 | +eslintInstance._originalLintText=eslintInstance.lintText; |
| 24 | +eslintInstance.lintText=mockLintTextSpy; |
| 25 | +returneslintInstance; |
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 | | -functionmockGetConfigForFile(filePath){ |
32 | | -if(mockGetConfigForFileSpy.throwError){ |
33 | | -throwmockGetConfigForFileSpy.throwError; |
| 31 | +functionmockCalculateConfigForFile(filePath){ |
| 32 | +if(mockCalculateConfigForFileSpy.throwError){ |
| 33 | +throwmockCalculateConfigForFileSpy.throwError; |
34 | 34 | } |
35 | 35 | if(!filePath){ |
36 | 36 | return{ |
@@ -71,10 +71,10 @@ function mockGetConfigForFile(filePath) { |
71 | 71 | } |
72 | 72 | } |
73 | 73 |
|
74 | | -functionmockExecuteOnText(...args){ |
75 | | -/* eslintbabel/no-invalid-this:0 */ |
76 | | -if(mockExecuteOnTextSpy.throwError){ |
77 | | -throwmockExecuteOnTextSpy.throwError; |
| 74 | +functionmockLintText(...args){ |
| 75 | +/* eslint no-invalid-this:0 */ |
| 76 | +if(mockLintTextSpy.throwError){ |
| 77 | +throwmockLintTextSpy.throwError; |
78 | 78 | } |
79 | | -returnthis._originalExecuteOnText(...args); |
| 79 | +returnthis._originalLintText(...args); |
80 | 80 | } |