diff --git a/test/e2e/tsdx-build-default.test.js b/test/e2e/tsdx-build-default.test.ts similarity index 95% rename from test/e2e/tsdx-build-default.test.js rename to test/e2e/tsdx-build-default.test.ts index 5a1c0f52..95814119 100644 --- a/test/e2e/tsdx-build-default.test.js +++ b/test/e2e/tsdx-build-default.test.ts @@ -1,6 +1,7 @@ -const shell = require('shelljs'); -const util = require('../utils/fixture'); -const { execWithCache } = require('../utils/shell'); +import * as shell from 'shelljs'; + +import * as util from '../utils/fixture'; +import { execWithCache } from '../utils/shell'; shell.config.silent = false; diff --git a/test/e2e/tsdx-build-invalid.test.js b/test/e2e/tsdx-build-invalid.test.ts similarity index 89% rename from test/e2e/tsdx-build-invalid.test.js rename to test/e2e/tsdx-build-invalid.test.ts index ccc3a937..3bf8c80b 100644 --- a/test/e2e/tsdx-build-invalid.test.js +++ b/test/e2e/tsdx-build-invalid.test.ts @@ -1,6 +1,7 @@ -const shell = require('shelljs'); -const util = require('../utils/fixture'); -const { execWithCache } = require('../utils/shell'); +import * as shell from 'shelljs'; + +import * as util from '../utils/fixture'; +import { execWithCache } from '../utils/shell'; shell.config.silent = false; diff --git a/test/e2e/tsdx-build-withTsconfig.test.js b/test/e2e/tsdx-build-withTsconfig.test.ts similarity index 94% rename from test/e2e/tsdx-build-withTsconfig.test.js rename to test/e2e/tsdx-build-withTsconfig.test.ts index 14aca52d..9474104d 100644 --- a/test/e2e/tsdx-build-withTsconfig.test.js +++ b/test/e2e/tsdx-build-withTsconfig.test.ts @@ -1,6 +1,7 @@ -const shell = require('shelljs'); -const util = require('../utils/fixture'); -const { execWithCache } = require('../utils/shell'); +import * as shell from 'shelljs'; + +import * as util from '../utils/fixture'; +import { execWithCache } from '../utils/shell'; shell.config.silent = false; diff --git a/test/e2e/tsdx-lint.test.js b/test/e2e/tsdx-lint.test.ts similarity index 96% rename from test/e2e/tsdx-lint.test.js rename to test/e2e/tsdx-lint.test.ts index 68831a49..f04327e3 100644 --- a/test/e2e/tsdx-lint.test.js +++ b/test/e2e/tsdx-lint.test.ts @@ -1,6 +1,6 @@ -const shell = require('shelljs'); +import * as shell from 'shelljs'; -const util = require('../utils/fixture'); +import * as util from '../utils/fixture'; shell.config.silent = true; diff --git a/test/integration/tsdx-build-options.test.js b/test/integration/tsdx-build-options.test.ts similarity index 93% rename from test/integration/tsdx-build-options.test.js rename to test/integration/tsdx-build-options.test.ts index db002bf6..d6c28644 100644 --- a/test/integration/tsdx-build-options.test.js +++ b/test/integration/tsdx-build-options.test.ts @@ -1,7 +1,7 @@ -const shell = require('shelljs'); +import * as shell from 'shelljs'; -const util = require('../utils/fixture'); -const { execWithCache } = require('../utils/shell'); +import * as util from '../utils/fixture'; +import { execWithCache } from '../utils/shell'; shell.config.silent = false; diff --git a/test/integration/tsdx-build-withBabel.test.js b/test/integration/tsdx-build-withBabel.test.ts similarity index 94% rename from test/integration/tsdx-build-withBabel.test.js rename to test/integration/tsdx-build-withBabel.test.ts index cb2b3b59..26b03762 100644 --- a/test/integration/tsdx-build-withBabel.test.js +++ b/test/integration/tsdx-build-withBabel.test.ts @@ -1,7 +1,7 @@ -const shell = require('shelljs'); +import * as shell from 'shelljs'; -const util = require('../utils/fixture'); -const { execWithCache, grep } = require('../utils/shell'); +import * as util from '../utils/fixture'; +import { execWithCache, grep } from '../utils/shell'; shell.config.silent = false; diff --git a/test/integration/tsdx-build-withConfig.test.js b/test/integration/tsdx-build-withConfig.test.ts similarity index 91% rename from test/integration/tsdx-build-withConfig.test.js rename to test/integration/tsdx-build-withConfig.test.ts index fa4d9ee5..ecd6d886 100644 --- a/test/integration/tsdx-build-withConfig.test.js +++ b/test/integration/tsdx-build-withConfig.test.ts @@ -1,8 +1,8 @@ -const shell = require('shelljs'); -const fs = require('fs-extra'); +import * as fs from 'fs-extra'; +import * as shell from 'shelljs'; -const util = require('../utils/fixture'); -const { execWithCache } = require('../utils/shell'); +import * as util from '../utils/fixture'; +import { execWithCache } from '../utils/shell'; shell.config.silent = false; diff --git a/test/utils/fixture.js b/test/utils/fixture.js deleted file mode 100644 index df4145df..00000000 --- a/test/utils/fixture.js +++ /dev/null @@ -1,28 +0,0 @@ -const shell = require('shelljs'); -const path = require('path'); -const rootDir = process.cwd(); - -shell.config.silent = true; - -module.exports = { - setupStageWithFixture: (testDir, stageName, fixtureName) => { - const stagePath = path.join(rootDir, stageName); - shell.mkdir(stagePath); - shell.exec( - `cp -a ${rootDir}/test/${testDir}/fixtures/${fixtureName}/. ${stagePath}/` - ); - shell.ln( - '-s', - path.join(rootDir, 'node_modules'), - path.join(stagePath, 'node_modules') - ); - shell.cd(stagePath); - }, - - teardownStage: stageName => { - shell.cd(rootDir); - shell.rm('-rf', path.join(rootDir, stageName)); - }, - - rootDir, -}; diff --git a/test/utils/fixture.ts b/test/utils/fixture.ts new file mode 100644 index 00000000..148b1e4c --- /dev/null +++ b/test/utils/fixture.ts @@ -0,0 +1,29 @@ +import * as path from 'path'; +import * as shell from 'shelljs'; + +export const rootDir = process.cwd(); + +shell.config.silent = true; + +export function setupStageWithFixture( + testDir: string, + stageName: string, + fixtureName: string +): void { + const stagePath = path.join(rootDir, stageName); + shell.mkdir(stagePath); + shell.exec( + `cp -a ${rootDir}/test/${testDir}/fixtures/${fixtureName}/. ${stagePath}/` + ); + shell.ln( + '-s', + path.join(rootDir, 'node_modules'), + path.join(stagePath, 'node_modules') + ); + shell.cd(stagePath); +} + +export function teardownStage(stageName: string): void { + shell.cd(rootDir); + shell.rm('-rf', path.join(rootDir, stageName)); +} diff --git a/test/utils/shell.js b/test/utils/shell.ts similarity index 67% rename from test/utils/shell.js rename to test/utils/shell.ts index c267ddc0..ee0b4b7a 100644 --- a/test/utils/shell.js +++ b/test/utils/shell.ts @@ -1,12 +1,15 @@ // this file contains helper utils for working with shell.js functions -const shell = require('shelljs'); +import * as shell from 'shelljs'; shell.config.silent = true; // simple shell.exec "cache" that doesn't re-run the same command twice in a row let prevCommand = ''; -let prevCommandOutput = {}; -function execWithCache(command, { noCache = false } = {}) { +let prevCommandOutput = {} as shell.ShellReturnValue; +export function execWithCache( + command: string, + { noCache = false } = {} +): shell.ShellReturnValue { // return the old output if (!noCache && prevCommand === command) return prevCommandOutput; @@ -15,7 +18,7 @@ function execWithCache(command, { noCache = false } = {}) { // reset if command is not to be cached if (noCache) { prevCommand = ''; - prevCommandOutput = {}; + prevCommandOutput = {} as shell.ShellReturnValue; } else { prevCommand = command; prevCommandOutput = output; @@ -24,19 +27,11 @@ function execWithCache(command, { noCache = false } = {}) { return output; } -// shelljs.grep wrapper -// @param {RegExp} pattern -// @param {string} fileName -// @returns {boolean} true if pattern has matches in file -function grep(pattern, fileName) { +// shell.js grep wrapper returns true if pattern has matches in file +export function grep(pattern: RegExp, fileName: string[]): boolean { const output = shell.grep(pattern, fileName); // output.code is always 0 regardless of matched/unmatched patterns // so need to test output.stdout // https://github.com/jaredpalmer/tsdx/pull/525#discussion_r395571779 return Boolean(output.stdout.match(pattern)); } - -module.exports = { - execWithCache, - grep, -};