Skip to content
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

test: minor cleanup #170

Merged
merged 1 commit into from Jun 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 19 additions & 25 deletions test/test-clean.ts
Expand Up @@ -33,47 +33,41 @@ const OPTIONS: Options = {
logger: {log: nop, error: nop, dir: nop}
};

test.failing.serial(
'should gracefully error if tsconfig is missing', async t => {
await withFixtures({}, async () => {
await clean(OPTIONS);
});
});
test.failing.serial('should gracefully error if tsconfig is missing', t => {
return withFixtures({}, async () => {
await clean(OPTIONS);
});
});

test.serial(
'should gracefully error if tsconfig does not have valid outDir',
async t => {
await withFixtures({'tsconfig.json': JSON.stringify({})}, async () => {
'should gracefully error if tsconfig does not have valid outDir', t => {
return withFixtures({'tsconfig.json': JSON.stringify({})}, async () => {
const deleted = await clean(OPTIONS);
t.is(deleted, false);
});
});

test.serial('should avoid deleting .', async t => {
await withFixtures(
test.serial('should avoid deleting .', t => {
return withFixtures(
{'tsconfig.json': JSON.stringify({compilerOptions: {outDir: '.'}})},
async () => {
const deleted = await clean(OPTIONS);
t.is(deleted, false);
});
});

test.failing.serial(
'should ensure that outDir is local to targetRoot', async t => {
await withFixtures(
{
'tsconfig.json':
JSON.stringify({compilerOptions: {outDir: '../out'}})
},
async () => {
const deleted = await clean(OPTIONS);
t.is(deleted, false);
});
});
test.failing.serial('should ensure that outDir is local to targetRoot', t => {
return withFixtures(
{'tsconfig.json': JSON.stringify({compilerOptions: {outDir: '../out'}})},
async () => {
const deleted = await clean(OPTIONS);
t.is(deleted, false);
});
});

test.serial('should remove outDir', async t => {
test.serial('should remove outDir', t => {
const OUT = 'outputDirectory';
await withFixtures(
return withFixtures(
{
'tsconfig.json': JSON.stringify({compilerOptions: {outDir: OUT}}),
[OUT]: {}
Expand Down
8 changes: 4 additions & 4 deletions test/test-format.ts
Expand Up @@ -35,17 +35,17 @@ const OPTIONS: Options = {
logger: {log: console.log, error: console.error, dir: nop}
};

test.serial('format should return false for ill-formatted files', async t => {
await withFixtures(
test.serial('format should return false for ill-formatted files', t => {
return withFixtures(
{'tsconfig.json': JSON.stringify({files: ['a.ts']}), 'a.ts': BAD_CODE},
async () => {
const result = await format.format(OPTIONS, [], false);
t.false(result);
});
});

test.serial('format should only look in root files', async t => {
await withFixtures(
test.serial('format should only look in root files', t => {
return withFixtures(
{
'tsconfig.json': JSON.stringify({files: ['a.ts']}),
'a.ts': 'import {foo} from \'./b\';\n',
Expand Down
102 changes: 49 additions & 53 deletions test/test-lint.ts
Expand Up @@ -40,15 +40,15 @@ const GOOD_CODE = `throw new Error('hello world');`;
const FIXABLE_CODE = 'const x : Array<string> = []';
const FIXABLE_CODE_FIXED = 'const x : string[] = [];';

test.serial('createProgram should return an object', async t => {
await withFixtures({'tsconfig.json': '{}'}, async () => {
test.serial('createProgram should return an object', t => {
return withFixtures({'tsconfig.json': '{}'}, async () => {
const program = lint.createProgram(OPTIONS);
t.truthy(program);
});
});

test.serial('lint should return true on good code', async t => {
await withFixtures(
test.serial('lint should return true on good code', t => {
return withFixtures(
{
'tsconfig.json': JSON.stringify({files: ['a.ts']}),
'a.ts': GOOD_CODE,
Expand All @@ -59,8 +59,8 @@ test.serial('lint should return true on good code', async t => {
});
});

test.serial('lint should return false on bad code', async t => {
await withFixtures(
test.serial('lint should return false on bad code', t => {
return withFixtures(
{
'tsconfig.json': JSON.stringify({files: ['a.ts']}),
'a.ts': BAD_CODE,
Expand All @@ -71,8 +71,8 @@ test.serial('lint should return false on bad code', async t => {
});
});

test.serial('lint should auto fix fixable errors', async t => {
await withFixtures(
test.serial('lint should auto fix fixable errors', t => {
return withFixtures(
{
'tsconfig.json': JSON.stringify({files: ['a.ts']}),
'a.ts': FIXABLE_CODE
Expand All @@ -86,8 +86,8 @@ test.serial('lint should auto fix fixable errors', async t => {
});
});

test.serial('lint should not auto fix on dry-run', async t => {
await withFixtures(
test.serial('lint should not auto fix on dry-run', t => {
return withFixtures(
{
'tsconfig.json': JSON.stringify({files: ['a.ts']}),
'a.ts': FIXABLE_CODE
Expand All @@ -102,8 +102,8 @@ test.serial('lint should not auto fix on dry-run', async t => {
});
});

test.serial('lint should lint files listed in tsconfig.files', async t => {
await withFixtures(
test.serial('lint should lint files listed in tsconfig.files', t => {
return withFixtures(
{
'tsconfig.json': JSON.stringify({files: ['a.ts']}),
'a.ts': GOOD_CODE,
Expand All @@ -118,7 +118,7 @@ test.serial('lint should lint files listed in tsconfig.files', async t => {
test.serial(
'lint should lint *.ts files when no files or inlcude has been specified',
async t => {
await withFixtures(
return withFixtures(
{
'tsconfig.json': JSON.stringify({}),
'a.ts': GOOD_CODE,
Expand All @@ -133,7 +133,7 @@ test.serial(
test.serial(
'lint should lint files listed in tsconfig.files when empty list is provided',
async t => {
await withFixtures(
return withFixtures(
{
'tsconfig.json': JSON.stringify({files: ['a.ts']}),
'a.ts': FIXABLE_CODE,
Expand All @@ -149,8 +149,8 @@ test.serial(
});


test.serial('lint should not lint files listed in exclude', async t => {
await withFixtures(
test.serial('lint should not lint files listed in exclude', t => {
return withFixtures(
{
'tsconfig.json': JSON.stringify({exclude: ['b.*']}),
'a.ts': GOOD_CODE,
Expand All @@ -162,8 +162,8 @@ test.serial('lint should not lint files listed in exclude', async t => {
});
});

test.serial('lint should lint globs listed in include', async t => {
await withFixtures(
test.serial('lint should lint globs listed in include', t => {
return withFixtures(
{
'tsconfig.json': JSON.stringify({include: ['dirb/*']}),
dira: {'a.ts': GOOD_CODE},
Expand All @@ -175,8 +175,8 @@ test.serial('lint should lint globs listed in include', async t => {
});
});

test.serial('lint should lint only specified files', async t => {
await withFixtures(
test.serial('lint should lint only specified files', t => {
return withFixtures(
{
'tsconfig.json': JSON.stringify({}),
dira: {'a.ts': GOOD_CODE},
Expand All @@ -190,8 +190,8 @@ test.serial('lint should lint only specified files', async t => {
});
});

test.serial('lint should throw for unrecognized files', async t => {
await withFixtures(
test.serial('lint should throw for unrecognized files', t => {
return withFixtures(
{
'tsconfig.json': JSON.stringify({}),
'a.ts': GOOD_CODE,
Expand All @@ -218,7 +218,7 @@ test.serial('lint should prefer user config file over default', async t => {
});

// User should be able to override the default config.
await withFixtures(
return withFixtures(
{
'tsconfig.json': JSON.stringify({files: ['a.ts']}),
'tslint.json': JSON.stringify({}),
Expand All @@ -230,36 +230,32 @@ test.serial('lint should prefer user config file over default', async t => {
});
});

test.serial(
'lint for specific files should use file-specific config', async t => {
const CODE_WITH_PARSEINT = 'parseInt(42);';
let logBuffer = '';
const optionsWithLog = Object.assign({}, OPTIONS, {
logger: {
log: (...args: string[]) => {
logBuffer += (args.join(' '));
},
error: nop,
dir: nop
}
test.serial('lint for specific files should use file-specific config', t => {
const CODE_WITH_PARSEINT = 'parseInt(42);';
let logBuffer = '';
const optionsWithLog = Object.assign({}, OPTIONS, {
logger: {
log: (...args: string[]) => {
logBuffer += (args.join(' '));
},
error: nop,
dir: nop
}
});
return withFixtures(
{
dira: {
'a.ts': CODE_WITH_PARSEINT,
// no tslint, so default should apply.
},
dirb: {'b.ts': CODE_WITH_PARSEINT, 'tslint.json': JSON.stringify({})}
},
async () => {
const okay = lint.lint(optionsWithLog, ['dira/a.ts', 'dirb/b.ts']);
t.false(okay);
t.regex(logBuffer, /dira\/a\.ts/);
t.notRegex(logBuffer, /dirb\/b\.ts/);
});
await withFixtures(
{
dira: {
'a.ts': CODE_WITH_PARSEINT,
// no tslint, so default should apply.
},
dirb: {
'b.ts': CODE_WITH_PARSEINT,
'tslint.json': JSON.stringify({})
}
},
async () => {
const okay = lint.lint(optionsWithLog, ['dira/a.ts', 'dirb/b.ts']);
t.false(okay);
t.regex(logBuffer, /dira\/a\.ts/);
t.notRegex(logBuffer, /dirb\/b\.ts/);
});
});
});

// TODO: test for when tsconfig.json is missing.