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: resolve gtsRootDir in tests #158

Merged
merged 1 commit into from Jun 1, 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
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this test deletec?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests in this fine weren't fully thought through, and this one in particular wasn't needed. Instead of fixing the bug in lint.ts, the tests were always ensuring that there was a tslint.json in the specific test directory. This test was testing that the bug correctly existed 🤣.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, this should had said.. fix the bug in the OPTIONS object construction.

// 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