8000 test(typescript-estree): add more persistentParse tests by bradzacher · Pull Request #1411 · typescript-eslint/typescript-eslint · GitHub
[go: up one dir, main page]

Skip to content

test(typescript-estree): add more persistentParse tests #1411

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 8, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 52 additions & 36 deletions packages/typescript-estree/tests/lib/persistentParse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,34 +97,36 @@ function baseTests(

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

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

// write a new file and attempt to parse it
writeFile(PROJECT_DIR, 'baz/bar');
writeFile(PROJECT_DIR, bazSlashBar);

// both files should parse fine now
expect(() => parseFile('foo', PROJECT_DIR)).not.toThrow();
expect(() => parseFile('baz/bar', PROJECT_DIR)).not.toThrow();
expect(() => parseFile(bazSlashBar, PROJECT_DIR)).not.toThrow();
});

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

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

// write a new file and attempt to parse it
renameFile(PROJECT_DIR, 'bar', 'baz/bar');
renameFile(PROJECT_DIR, 'bar', bazSlashBar);

// both files should parse fine now
expect(() => parseFile('foo', PROJECT_DIR)).not.toThrow();
expect(() => parseFile('baz/bar', PROJECT_DIR)).not.toThrow();
expect(() => parseFile(bazSlashBar, PROJECT_DIR)).not.toThrow();
});

it('reacts to changes in the tsconfig', () => {
Expand All @@ -140,36 +142,6 @@ function baseTests(
expect(() => parseFile('foo', PROJECT_DIR)).not.toThrow();
expect(() => parseFile('bar', PROJECT_DIR)).not.toThrow();
});

it('handles tsconfigs with no includes/excludes (single level)', () => {
const PROJECT_DIR = setup({}, false);

// parse once to: assert the config as correct, and to make sure the program is setup
expect(() => parseFile('foo', PROJECT_DIR)).not.toThrow();
expect(() => parseFile('bar', PROJECT_DIR)).toThrow();

// write a new file and attempt to parse it
writeFile(PROJECT_DIR, 'bar');

expect(() => parseFile('foo', PROJECT_DIR)).not.toThrow();
expect(() => parseFile('bar', PROJECT_DIR)).not.toThrow();
});

it('handles tsconfigs with no includes/excludes (nested)', () => {
const PROJECT_DIR = setup({}, false);

// parse once to: assert the config as correct, and to make sure the program is setup
expect(() => parseFile('foo', PROJECT_DIR)).not.toThrow();
expect(() => parseFile('baz/bar', PROJECT_DIR)).toThrow();

// write a new file and attempt to parse it
writeFile(PROJECT_DIR, 'baz/bar');

expect(() => parseFile('foo', PROJECT_DIR)).not.toThrow();
expect(() => parseFile('baz/bar', PROJECT_DIR)).not.toThrow();
});

// TODO - support the complex monorepo case with a tsconfig with no include/exclude
}

describe('persistent parse', () => {
Expand Down Expand Up @@ -213,5 +185,49 @@ describe('persistent parse', () => {
const tsConfigIncludeAll = {};

baseTests(tsConfigExcludeBar, tsConfigIncludeAll);

it('handles tsconfigs with no includes/excludes (single level)', () => {
const PROJECT_DIR = setup({}, false);

// parse once to: assert the config as correct, and to make sure the program is setup
expect(() => parseFile('foo', PROJECT_DIR)).not.toThrow();
expect(() => parseFile('bar', PROJECT_DIR)).toThrow();

// write a new file and attempt to parse it
writeFile(PROJECT_DIR, 'bar');

expect(() => parseFile('foo', PROJECT_DIR)).not.toThrow();
expect(() => parseFile('bar', PROJECT_DIR)).not.toThrow();
});

it('handles tsconfigs with no includes/excludes (nested)', () => {
const PROJECT_DIR = setup({}, false);
const bazSlashBar = path.join('baz', 'bar') as 'baz/bar';

// parse once to: assert the config as correct, and to make sure the program is setup
expect(() => parseFile('foo', PROJECT_DIR)).not.toThrow();
expect(() => parseFile(bazSlashBar, PROJECT_DIR)).toThrow();

// write a new file and attempt to parse it
writeFile(PROJECT_DIR, bazSlashBar);

expect(() => parseFile('foo', PROJECT_DIR)).not.toThrow();
expect(() => parseFile(bazSlashBar, PROJECT_DIR)).not.toThrow();
});
});

/*
If there is no includes, then typescript will ask for a slightly different set of watchers.
*/
describe('tsconfig with overlapping globs', () => {
const tsConfigExcludeBar = {
include: ['./*', './**/*', './src/**/*'],
exclude: ['./src/bar.ts'],
};
const tsConfigIncludeAll = {
include: ['./*', './**/*', './src/**/*'],
};

baseTests(tsConfigExcludeBar, tsConfigIncludeAll);
});
});
0