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

Use imports instead of requires in tests #340

Merged
merged 2 commits into from
Feb 23, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,4 @@ module.exports = {
],
'@babel/preset-typescript',
],
plugins: [
'@babel/plugin-proposal-nullish-coalescing-operator', // TODO: Will become unnecessary soon: https://github.com/babel/babel/issues/10690
'@babel/plugin-proposal-optional-chaining', // TODO: Will become unnecessary soon: https://github.com/babel/babel/issues/10690
],
};
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@
},
"devDependencies": {
"@babel/core": "^7.7.5",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.7.4",
"@babel/plugin-proposal-optional-chaining": "^7.7.5",
"@babel/preset-env": "^7.7.6",
"@babel/preset-typescript": "^7.7.4",
"@types/cli-table": "^0.3.0",
Expand All @@ -48,6 +46,7 @@
"@types/semver": "^7.1.0",
"@typescript-eslint/eslint-plugin": "^2.23.0",
"@typescript-eslint/parser": "^2.23.0",
"babel-jest": "^26.6.3",
"eslint": "^6.4.0",
"eslint-config-prettier": "^6.3.0",
"eslint-plugin-import": "^2.18.2",
Expand Down
4 changes: 2 additions & 2 deletions test/print-pretty-error.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-env jest */

// Dependencies
const printPrettyError = require('../dist/print-pretty-error').default;
const chalk = require('../dist/chalk').default;
import printPrettyError from '../src/print-pretty-error';
import chalk from '../src/chalk';

// Holders for capturing console.error output
let spy;
Expand Down
2 changes: 1 addition & 1 deletion test/process-arguments.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-env jest */

// Dependencies
const processArguments = require('../dist/process-arguments').default;
import processArguments from '../src/process-arguments';

// Tests
describe('#processArguments()', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/program-bad-onstart.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-env jest */

// Dependencies
const runProgram = require('./run-program');
import runProgram from './run-program';

// Initialize
const entryFile = `${__dirname}/programs/bad-onstart/cli/entry.js`;
Expand Down
4 changes: 2 additions & 2 deletions test/program-es6-imports.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-env jest */

// Dependencies
const runProgram = require('./run-program');
const semver = require('semver');
import runProgram from './run-program';
import semver from 'semver';

// Initialize
const entryFile = `${__dirname}/programs/es6-imports/cli/entry.js`;
Expand Down
6 changes: 3 additions & 3 deletions test/program-global-bin.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* eslint-env jest */

// Dependencies
const runProgram = require('./run-program');
const path = require('path');
const { exec } = require('child_process');
import runProgram from './run-program';
import path from 'path';
import { exec } from 'child_process';

// Link this program
beforeAll(() => {
Expand Down
2 changes: 1 addition & 1 deletion test/program-pizza-ordering.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-env jest */

// Dependencies
const runProgram = require('./run-program');
import runProgram from './run-program';

// Initialize
const entryFile = `${__dirname}/programs/pizza-ordering/cli/entry.js`;
Expand Down
2 changes: 1 addition & 1 deletion test/program-typescript.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-env jest */

// Dependencies
const runProgram = require('./run-program');
import runProgram from './run-program';

// Initialize
const entryFile = `${__dirname}/programs/typescript/cli/entry.js`;
Expand Down
6 changes: 3 additions & 3 deletions test/run-program.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Dependencies
const { exec } = require('child_process');
import { exec } from 'child_process';

// Remove ANSI formatting
function removeFormatting(text) {
Expand All @@ -10,7 +10,7 @@ function removeFormatting(text) {
}

// Test runner
module.exports = function runProgram(command) {
export default function runProgram(command: string): Promise<{ stdout: string; stderr: string }> {
// Return a promise
return new Promise((resolve, reject) => {
// Launch the program
Expand All @@ -33,4 +33,4 @@ module.exports = function runProgram(command) {
});
});
});
};
}
4 changes: 2 additions & 2 deletions test/screens.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
/* eslint no-control-regex: "off" */

// Dependencies
const defaultSettings = require('../dist/default-settings').default;
const screens = require('../dist/screens').default;
import defaultSettings from '../src/default-settings';
import screens from '../src/screens';

// Remove ANSI formatting
function removeFormatting(text) {
Expand Down
4 changes: 2 additions & 2 deletions test/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-env jest */

// Dependencies
const defaultSettings = require('../dist/default-settings').default;
const utils = require('../dist/utils').default;
import defaultSettings from '../src/default-settings';
import utils from '../src/utils';

const settingsBadStructure = {
...defaultSettings,
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@
"@babel/helper-plugin-utils" "^7.10.4"
"@babel/plugin-syntax-logical-assignment-operators" "^7.10.4"

"@babel/plugin-proposal-nullish-coalescing-operator@^7.12.1", "@babel/plugin-proposal-nullish-coalescing-operator@^7.7.4":
"@babel/plugin-proposal-nullish-coalescing-operator@^7.12.1":
version "7.12.1"
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-nullish-coalescing-operator/-/plugin-proposal-nullish-coalescing-operator-7.12.1.tgz#3ed4fff31c015e7f3f1467f190dbe545cd7b046c"
integrity sha512-nZY0ESiaQDI1y96+jk6VxMOaL4LPo/QDHBqL+SF3/vl6dHkTwHlOI8L4ZwuRBHgakRBw5zsVylel7QPbbGuYgg==
Expand Down Expand Up @@ -369,7 +369,7 @@
"@babel/helper-plugin-utils" "^7.10.4"
"@babel/plugin-syntax-optional-catch-binding" "^7.8.0"

"@babel/plugin-proposal-optional-chaining@^7.12.7", "@babel/plugin-proposal-optional-chaining@^7.7.5":
"@babel/plugin-proposal-optional-chaining@^7.12.7":
version "7.12.7"
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-optional-chaining/-/plugin-proposal-optional-chaining-7.12.7.tgz#e02f0ea1b5dc59d401ec16fb824679f683d3303c"
integrity sha512-4ovylXZ0PWmwoOvhU2vhnzVNnm88/Sm9nx7V8BPgMvAzn5zDou3/Awy0EjglyubVHasJj+XCEkr/r1X3P5elCA==
Expand Down