Skip to content

Commit

Permalink
test(typescript-estree): add more persistentParse tests (#1411)
Browse files Browse the repository at this point in the history
  • Loading branch information
bradzacher committed Jan 8, 2020
1 parent aee7238 commit 6aa6bc7
Showing 1 changed file with 52 additions and 36 deletions.
88 changes: 52 additions & 36 deletions packages/typescript-estree/tests/lib/persistentParse.ts
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 comments on commit 6aa6bc7

Please sign in to comment.