-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/** | ||
* Copyright 2017 Google Inc. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import test from 'ava'; | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
import {clean} from '../src/clean'; | ||
import {nop} from '../src/util'; | ||
import {Options} from '../src/cli'; | ||
import {withFixtures} from './fixtures'; | ||
|
||
const OPTIONS: Options = { | ||
gtsRootDir: './', | ||
targetRootDir: './', | ||
dryRun: false, | ||
yes: false, | ||
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); | ||
t.pass(); | ||
}); | ||
}); | ||
|
||
test.serial( | ||
'should gracefully error if tsconfig does not have valid outDir', | ||
async t => { | ||
await withFixtures({'tsconfig.json': JSON.stringify({})}, async () => { | ||
const deleted = await clean(OPTIONS); | ||
t.is(deleted, false); | ||
}); | ||
}); | ||
|
||
test.serial('should avoid deleting .', async t => { | ||
await 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.serial('should remove outDir', async t => { | ||
const OUT = 'outputDirectory'; | ||
await withFixtures( | ||
{ | ||
'tsconfig.json': JSON.stringify({compilerOptions: {outDir: OUT}}), | ||
[OUT]: {} | ||
}, | ||
async (dir) => { | ||
const outputPath = path.join(dir, OUT); | ||
// make sure the output directory exists. | ||
fs.accessSync(outputPath); | ||
const deleted = await clean(OPTIONS); | ||
t.is(deleted, true); | ||
// make sure the directory has been deleted. | ||
t.throws(() => { | ||
fs.accessSync(outputPath); | ||
}); | ||
}); | ||
}); |