Skip to content

Commit

Permalink
test: resolve gtsRootDir in tests
Browse files Browse the repository at this point in the history
This ensures that the tests are independent of where they are run from.
Remove unnecessary lint test. Improve lint tests to avoid passing in
lint config.
  • Loading branch information
ofrobots committed Jun 1, 2018
1 parent 86ffb3b commit ea50344
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 28 deletions.
2 changes: 1 addition & 1 deletion test/test-clean.ts
Expand Up @@ -25,7 +25,7 @@ import {nop} from '../src/util';
import {withFixtures} from './fixtures';

const OPTIONS: Options = {
gtsRootDir: './',
gtsRootDir: path.resolve(__dirname, '../..'),
targetRootDir: './',
dryRun: false,
yes: false,
Expand Down
3 changes: 2 additions & 1 deletion test/test-format.ts
Expand Up @@ -15,6 +15,7 @@
*/

import test from 'ava';
import * as path from 'path';

import {Options} from '../src/cli';
import * as format from '../src/format';
Expand All @@ -26,7 +27,7 @@ import {withFixtures} from './fixtures';
const BAD_CODE = 'export const foo = 2; ';

const OPTIONS: Options = {
gtsRootDir: './',
gtsRootDir: path.resolve(__dirname, '../..'),
targetRootDir: './',
dryRun: false,
yes: false,
Expand Down
28 changes: 2 additions & 26 deletions test/test-lint.ts
Expand Up @@ -15,6 +15,7 @@
*/

import test from 'ava';
import * as path from 'path';

import {Options} from '../src/cli';
import * as lint from '../src/lint';
Expand All @@ -23,7 +24,7 @@ import {nop} from '../src/util';
import {withFixtures} from './fixtures';

const OPTIONS: Options = {
gtsRootDir: './',
gtsRootDir: path.resolve(__dirname, '../..'),
targetRootDir: './',
dryRun: false,
yes: false,
Expand All @@ -34,36 +35,18 @@ const OPTIONS: Options = {
const BAD_CODE = `throw 'hello world';`;
const GOOD_CODE = `throw new Error('hello world');`;

const TSLINT_CONFIG = require('../../tslint.json');

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

// TODO: make the error friendlier. This error implies that our module messed
// up, or is not installed/integrated properly.
test.serial('lint should throw error if tslint is missing', async t => {
await withFixtures(
{
'tsconfig.json': JSON.stringify({files: ['a.ts']}),
'a.ts': GOOD_CODE,
},
async () => {
const err = t.throws(() => {
lint.lint(OPTIONS);
});
t.truthy(err.message.match('Could not find config.*tslint\.json'));
});
});

test.serial('lint should return true on good code', async t => {
await withFixtures(
{
'tsconfig.json': JSON.stringify({files: ['a.ts']}),
'tslint.json': JSON.stringify(TSLINT_CONFIG),
'a.ts': GOOD_CODE,
},
async () => {
Expand All @@ -76,7 +59,6 @@ test.serial('lint should return false on bad code', async t => {
await withFixtures(
{
'tsconfig.json': JSON.stringify({files: ['a.ts']}),
'tslint.json': JSON.stringify(TSLINT_CONFIG),
'a.ts': BAD_CODE,
},
async () => {
Expand All @@ -89,7 +71,6 @@ test.serial('lint should lint files listed in tsconfig.files', async t => {
await withFixtures(
{
'tsconfig.json': JSON.stringify({files: ['a.ts']}),
'tslint.json': JSON.stringify(TSLINT_CONFIG),
'a.ts': GOOD_CODE,
'b.ts': BAD_CODE
},
Expand All @@ -105,7 +86,6 @@ test.serial(
await withFixtures(
{
'tsconfig.json': JSON.stringify({}),
'tslint.json': JSON.stringify(TSLINT_CONFIG),
'a.ts': GOOD_CODE,
'b.ts': BAD_CODE
},
Expand All @@ -119,7 +99,6 @@ test.serial('lint should not lint files listed in exclude', async t => {
await withFixtures(
{
'tsconfig.json': JSON.stringify({exclude: ['b.*']}),
'tslint.json': JSON.stringify(TSLINT_CONFIG),
'a.ts': GOOD_CODE,
'b.ts': BAD_CODE
},
Expand All @@ -133,7 +112,6 @@ test.serial('lint should lint globs listed in include', async t => {
await withFixtures(
{
'tsconfig.json': JSON.stringify({include: ['dirb/*']}),
'tslint.json': JSON.stringify(TSLINT_CONFIG),
dira: {'a.ts': GOOD_CODE},
dirb: {'b.ts': BAD_CODE}
},
Expand All @@ -147,7 +125,6 @@ test.serial('lint should lint only specified files', async t => {
await withFixtures(
{
'tsconfig.json': JSON.stringify({}),
'tslint.json': JSON.stringify(TSLINT_CONFIG),
dira: {'a.ts': GOOD_CODE},
dirb: {'b.ts': BAD_CODE}
},
Expand All @@ -163,7 +140,6 @@ test.serial('lint should not throw for unrecognized files', async t => {
await withFixtures(
{
'tsconfig.json': JSON.stringify({}),
'tslint.json': JSON.stringify(TSLINT_CONFIG),
'a.ts': GOOD_CODE,
},
async () => {
Expand Down

0 comments on commit ea50344

Please sign in to comment.