8000 test(typescript-estree): add more persistentParse tests (#1411) · CarsonF/typescript-eslint@6aa6bc7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6aa6bc7

Browse files
authored
test(typescript-estree): add more persistentParse tests (typescript-eslint#1411)
1 parent aee7238 commit 6aa6bc7

File tree

1 file changed

+52
-36
lines changed

1 file changed

+52
-36
lines changed

packages/typescript-estree/tests/lib/persistentParse.ts

Lines changed: 52 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -97,34 +97,36 @@ function baseTests(
9797

9898
it('allows parsing of deeply nested new files', () => {
9999
const PROJECT_DIR = setup(tsConfigIncludeAll, false);
100+
const bazSlashBar = path.join('baz', 'bar') as 'baz/bar';
100101

101102
// parse once to: assert the config as correct, and to make sure the program is setup
102103
expect(() => parseFile('foo', PROJECT_DIR)).not.toThrow();
103104
// bar should throw because it doesn't exist yet
104-
expect(() => parseFile('baz/bar', PROJECT_DIR)).toThrow();
105+
expect(() => parseFile(bazSlashBar, PROJECT_DIR)).toThrow();
105106

106107
// write a new file and attempt to parse it
107-
writeFile(PROJECT_DIR, 'baz/bar');
108+
writeFile(PROJECT_DIR, bazSlashBar);
108109

109110
// both files should parse fine now
110111
expect(() => parseFile('foo', PROJECT_DIR)).not.toThrow();
111-
expect(() => parseFile('baz/bar', PROJECT_DIR)).not.toThrow();
112+
expect(() => parseFile(bazSlashBar, PROJECT_DIR)).not.toThrow();
112113
});
113114

114115
it('allows renaming of files', () => {
115116
const PROJECT_DIR = setup(tsConfigIncludeAll, true);
117+
const bazSlashBar = path.join('baz', 'bar') as 'baz/bar';
116118

117119
// parse once to: assert the config as correct, and to make sure the program is setup
118120
expect(() => parseFile('foo', PROJECT_DIR)).not.toThrow();
119121
// bar should throw because it doesn't exist yet
120-
expect(() => parseFile('baz/bar', PROJECT_DIR)).toThrow();
122+
expect(() => parseFile(bazSlashBar, PROJECT_DIR)).toThrow();
121123

122124
// write a new file and attempt to parse it
123-
renameFile(PROJECT_DIR, 'bar', 'baz/bar');
125+
renameFile(PROJECT_DIR, 'bar', bazSlashBar);
124126

125127
// both files should parse fine now
126128
expect(() => parseFile('foo', PROJECT_DIR)).not.toThrow();
127-
expect(() => parseFile('baz/bar', PROJECT_DIR)).not.toThrow();
129+
expect(() => parseFile(bazSlashBar, PROJECT_DIR)).not.toThrow();
128130
});
129131

130132
it('reacts to changes in the tsconfig', () => {
@@ -140,36 +142,6 @@ function baseTests(
140142
expect(() => parseFile('foo', PROJECT_DIR)).not.toThrow();
141143
expect(() => parseFile('bar', PROJECT_DIR)).not.toThrow();
142144
});
143-
144-
it('handles tsconfigs with no includes/excludes (single level)', () => {
145-
const PROJECT_DIR = setup({}, false);
146-
147-
// parse once to: assert the config as correct, and to make sure the program is setup
148-
expect(() => parseFile('foo', PROJECT_DIR)).not.toThrow();
149-
expect(() => parseFile('bar', PROJECT_DIR)).toThrow();
150-
151-
// write a new file and attempt to parse it
152-
writeFile(PROJECT_DIR, 'bar');
153-
154-
expect(() => parseFile('foo', PROJECT_DIR)).not.toThrow();
155-
expect(() => parseFile('bar', PROJECT_DIR)).not.toThrow();
156-
});
157-
158-
it('handles tsconfigs with no includes/excludes (nested)', () => {
159-
const PROJECT_DIR = setup({}, false);
160-
161-
// parse once to: assert the config as correct, and to make sure the program is setup
162-
expect(() => parseFile('foo', PROJECT_DIR)).not.toThrow();
163-
expect(() => parseFile('baz/bar', PROJECT_DIR)).toThrow();
164-
165-
// write a new file and attempt to parse it
166-
writeFile(PROJECT_DIR, 'baz/bar');
167-
168-
expect(() => parseFile('foo', PROJECT_DIR)).not.toThrow();
169-
expect(() => parseFile('baz/bar', PROJECT_DIR)).not.toThrow();
170-
});
171-
172-
// TODO - support the complex monorepo case with a tsconfig with no include/exclude
173145
}
174146

175147
describe('persistent parse', () => {
@@ -213,5 +185,49 @@ describe('persistent parse', () => {
213185
const tsConfigIncludeAll = {};
214186

215187
baseTests(tsConfigExcludeBar, tsConfigIncludeAll);
188+
189+
it('handles tsconfigs with no includes/excludes (single level)', () => {
190+
const PROJECT_DIR = setup( 57AE {}, false);
191+
192+
// parse once to: assert the config as correct, and to make sure the program is setup
193+
expect(() => parseFile('foo', PROJECT_DIR)).not.toThrow();
194+
expect(() => parseFile('bar', PROJECT_DIR)).toThrow();
195+
196+
// write a new file and attempt to parse it
197+
writeFile(PROJECT_DIR, 'bar');
198+
199+
expect(() => parseFile('foo', PROJECT_DIR)).not.toThrow();
200+
expect(() => parseFile('bar', PROJECT_DIR)).not.toThrow();
201+
});
202+
203+
it('handles tsconfigs with no includes/excludes (nested)', () => {
204+
const PROJECT_DIR = setup({}, false);
205+
const bazSlashBar = path.join('baz', 'bar') as 'baz/bar';
206+
207+
// parse once to: assert the config as correct, and to make sure the program is setup
208+
expect(() => parseFile('foo', PROJECT_DIR)).not.toThrow();
209+
expect(() => parseFile(bazSlashBar, PROJECT_DIR)).toThrow();
210+
211+
// write a new file and attempt to parse it
212+
writeFile(PROJECT_DIR, bazSlashBar);
213+
214+
expect(() => parseFile('foo', PROJECT_DIR)).not.toThrow();
215+
expect(() => parseFile(bazSlashBar, PROJECT_DIR)).not.toThrow();
216+
});
217+
});
218+
219+
/*
220+
If there is no includes, then typescript will ask for a slightly different set of watchers.
221+
*/
222+
describe('tsconfig with overlapping globs', () => {
223+
const tsConfigExcludeBar = {
224+
include: ['./*', './**/*', './src/**/*'],
225+
exclude: ['./src/bar.ts'],
226+
};
227+
const tsConfigIncludeAll = {
228+
include: ['./*', './**/*', './src/**/*'],
229+
};
230+
231+
baseTests(tsConfigExcludeBar, tsConfigIncludeAll);
216232
});
217233
});

0 commit comments

Comments
 (0)
0