Skip to content

Commit 86a7879

Browse files
committed
create .tmp dir if does not exist
1 parent 04fe166 commit 86a7879

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
node_modules
22
src/*.js
33
test/**/*.ts
4-
.tmp/**.*
4+
.tmp/*.js

lib/writeTests/index.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
"use strict";
2-
var fs_1 = require('fs');
2+
var fs = require('fs');
3+
var path_1 = require('path');
34
var process_console_log_1 = require('process-console-log');
45
var import_paths_1 = require('./import-paths');
56
var helpers_1 = require('./helpers');
7+
var tmpPath = path_1.join(__dirname, '..', '..', '.tmp');
68
function writeTest(_a) {
79
var dir = _a.dir, tests = _a.tests, testPath = _a.testPath;
810
var fixImports = import_paths_1.default(dir, tests);
@@ -11,14 +13,20 @@ function writeTest(_a) {
1113
.concat(helpers_1.default(dir))
1214
.concat(fixImports)
1315
.concat('\n}());');
16+
writeTestFile(testPath, output);
17+
}
18+
Object.defineProperty(exports, "__esModule", { value: true });
19+
exports.default = writeTest;
20+
function writeTestFile(testPath, output) {
21+
if (!fs.existsSync(tmpPath)) {
22+
fs.mkdirSync(tmpPath);
23+
}
1424
return new Promise(function (resolve, reject) {
15-
fs_1.writeFile(testPath, output, function (err) {
25+
fs.writeFile(testPath, output, function (err) {
1626
if (err) {
1727
reject(err);
1828
}
1929
resolve();
2030
});
2131
});
2232
}
23-
Object.defineProperty(exports, "__esModule", { value: true });
24-
exports.default = writeTest;

src/writeTests/index.ts

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
import {writeFile} from 'fs';
2-
import {logger} from 'process-console-log';
1+
import * as fs from 'fs';
2+
import { join } from 'path';
3+
import { logger } from 'process-console-log';
34
import importPaths from './import-paths';
45
import helpers from './helpers';
56

7+
const tmpPath = join(__dirname, '..', '..', '.tmp');
8+
69
export default function writeTest({ dir, tests, testPath }) {
710

811
// fix import paths relative to project dir instead of test runner
@@ -20,9 +23,17 @@ export default function writeTest({ dir, tests, testPath }) {
2023
.concat(fixImports)
2124
.concat('\n}());');
2225

26+
writeTestFile(testPath, output);
27+
}
28+
29+
function writeTestFile(testPath: string, output: string) {
30+
// create .tmp directory if doesn't exist
31+
if (!fs.existsSync(tmpPath)) {
32+
fs.mkdirSync(tmpPath);
33+
}
2334
return new Promise((resolve, reject) => {
2435
// write test file
25-
writeFile(testPath, output, (err) => {
36+
fs.writeFile(testPath, output, (err) => {
2637
if (err) { reject(err); }
2738
resolve();
2839
});

0 commit comments

Comments
 (0)