Skip to content

Commit

Permalink
Update deps, change target, refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
tough-griff committed Oct 20, 2021
1 parent 3bbadc1 commit 2d84ac4
Show file tree
Hide file tree
Showing 10 changed files with 4,043 additions and 7,369 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ jobs:
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Update npm
shell: bash
run: npm install -g npm@8
- name: Install dependencies
shell: bash
run: npm ci
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# rrepl [![npm](https://img.shields.io/npm/v/rrepl.svg)](https://www.npmjs.com/package/rrepl) [![Actions Status](https://github.com/tough-griff/rrepl/workflows/Test/badge.svg)](https://github.com/tough-griff/rrepl/actions) [![codecov](https://codecov.io/gh/tough-griff/rrepl/branch/main/graph/badge.svg)](https://codecov.io/gh/tough-griff/rrepl)
# rrepl

[![npm](https://img.shields.io/npm/v/rrepl)](https://www.npmjs.com/package/rrepl)
[![build](https://img.shields.io/github/workflow/status/tough-griff/rrepl/Test)](https://github.com/tough-griff/rrepl/actions/workflows/test.yml)
[![codecov](https://img.shields.io/codecov/c/github/tough-griff/rrepl)](https://codecov.io/gh/tough-griff/rrepl)

> An improved node REPL with support for configuration.
Expand Down
9 changes: 0 additions & 9 deletions jest.config.js

This file was deleted.

11,025 changes: 3,859 additions & 7,166 deletions package-lock.json

Large diffs are not rendered by default.

67 changes: 40 additions & 27 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,50 +22,51 @@
"lib/index.d.ts",
"lib/index.js"
],
"engines": {
"node": ">=12.13 <17"
},
"scripts": {
"prebuild": "tsc --build --clean src/",
"build": "tsc --build src/",
"postbuild": "node -e \"require('fs').chmodSync('$npm_package_bin_rrepl', 0o755)\"",
"clean": "tsc --build src/ --clean",
"lint": "eslint src/",
"prepack": "npm run clean && npm run build",
"prepare": "husky install",
"prestart": "npm run build",
"start": "node lib/cli",
"start": "ts-node src/cli",
"test": "jest src/",
"test:cov": "nyc --reporter lcov --reporter text npm test"
},
"engines": {
"node": ">=12.13"
},
"dependencies": {
"chalk": "^4.1.0",
"commander": "^7.2.0"
"chalk": "^4.1.2",
"commander": "^8.2.0"
},
"devDependencies": {
"@tough-griff/eslint-config-typescript": "^1.1.9",
"@tsconfig/node10": "^1.0.7",
"@types/jest": "^26.0.22",
"@types/lodash": "^4.14.168",
"@types/node": "^14.14.41",
"@types/tmp": "^0.2.0",
"@typescript-eslint/eslint-plugin": "^4.21.0",
"@typescript-eslint/parser": "^4.21.0",
"codecov": "^3.8.1",
"eslint": "^7.23.0",
"@tough-griff/eslint-config-typescript": "^1.1.12",
"@tsconfig/node12": "^1.0.9",
"@types/jest": "^27.0.2",
"@types/lodash": "^4.14.175",
"@types/node": "^12.20.33",
"@types/tmp": "^0.2.1",
"@typescript-eslint/eslint-plugin": "^5.1.0",
"@typescript-eslint/parser": "^5.1.0",
"codecov": "^3.8.3",
"eslint": "^7.32.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-prettier": "^3.3.1",
"husky": "^6.0.0",
"jest": "^26.6.3",
"lint-staged": "^10.5.4",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-prettier": "^4.0.0",
"husky": "^7.0.2",
"jest": "^27.3.1",
"jest-if": "^1.0.1",
"lint-staged": "^11.2.3",
"lodash": "^4.17.21",
"nyc": "^15.1.0",
"prettier": "^2.2.1",
"prettier": "^2.4.1",
"tmp-promise": "^3.0.2",
"ts-jest": "^26.5.4",
"ts-node": "^9.1.1",
"typescript": "^4.2.3"
"ts-jest": "^27.0.7",
"ts-node": "^10.3.0",
"typescript": "^4.4.4"
},
"eslintConfig": {
"extends": "@tough-griff/eslint-config-typescript",
Expand All @@ -78,6 +79,18 @@
"import/first": "off"
}
},
"jest": {
"preset": "ts-jest",
"testEnvironment": "node",
"globals": {
"ts-jest": {
"tsconfig": "./src/tsconfig.json"
}
},
"setupFilesAfterEnv": [
"jest-if"
]
},
"lint-staged": {
"*.js{,on}": "prettier --write",
"*.md": "prettier --write",
Expand Down
228 changes: 103 additions & 125 deletions src/cli.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { fork } from 'child_process';
import { platform } from 'os';
import { file } from 'tmp-promise';
import { withFile } from 'tmp-promise';

const TIMEOUT = 6_000;
jest.setTimeout(6_000);

class Result {
argv: ReadonlyArray<string>;
Expand Down Expand Up @@ -70,147 +70,125 @@ const rrepl = (
});
};

const itif = (condition: boolean): jest.It => (condition ? it : it.skip);

it(
'returns an exit code of 0',
async () => {
const result = await rrepl(['-c', '.noderc.test.js']);
expect(result.errs).toHaveLength(0);
expect(result).toHaveProperty('signal', null);
expect(result).toHaveProperty('code', 0);
expect(result.stderrMonitor).not.toHaveBeenCalled();
},
TIMEOUT,
);

it(
'returns an exit code of 0 and logs debug information in verbose mode',
async () => {
const result = await rrepl(['-c', '.noderc.test.js', '-v']);
expect(result.errs).toHaveLength(0);
expect(result).toHaveProperty('signal', null);
expect(result).toHaveProperty('code', 0);
expect(result.stdoutMonitor).toHaveBeenCalledWith(
expect.stringMatching(
/\[DEBUG\] Configuring history at .*\.node_repl_history/,
),
);
expect(result.stdoutMonitor).toHaveBeenCalledWith(
expect.stringMatching(
/\[DEBUG\] Using configuration at .*\.noderc\.test\.js/,
),
);
expect(result.stderrMonitor).not.toHaveBeenCalled();
},
TIMEOUT,
);

it(
'returns an exit code of 0 and skips history setup in verbose mode',
async () => {
const result = await rrepl(['-c', '.noderc.test.js', '-v'], {
NODE_REPL_HISTORY: '',
});
expect(result.errs).toHaveLength(0);
expect(result).toHaveProperty('signal', null);
expect(result).toHaveProperty('code', 0);
expect(result.stdoutMonitor).toHaveBeenCalledWith(
expect.stringContaining('[DEBUG] Skipping history setup'),
);
expect(result.stderrMonitor).not.toHaveBeenCalled();
},
TIMEOUT,
);

it(
'returns an exit code of 0 when defaulting to ~/.noderc',
async () => {
const result = await rrepl([], { NODE_REPL_MODE: 'strict' });
expect(result.errs).toHaveLength(0);
expect(result).toHaveProperty('signal', null);
expect(result).toHaveProperty('code', 0);
expect(result.stderrMonitor).not.toHaveBeenCalled();
},
TIMEOUT,
);

it(
'returns an exit code of 0 when passed a bad config path',
async () => {
const result = await rrepl(['-c', '.noderc.noexists.test.js']);
expect(result.errs).toHaveLength(0);
expect(result).toHaveProperty('signal', null);
expect(result).toHaveProperty('code', 0);
expect(result.stderrMonitor).not.toHaveBeenCalled();
},
TIMEOUT,
);

it(
'returns an exit code of 0 and logs debug messages when passed a bad config path in verbose mode',
async () => {
const result = await rrepl(['-c', '.noderc.noexists.test.js', '-v']);
expect(result.errs).toHaveLength(0);
expect(result).toHaveProperty('signal', null);
expect(result).toHaveProperty('code', 0);
expect(result.stdoutMonitor).toHaveBeenCalledWith(
expect.stringMatching(
/\[DEBUG\] No configuration found at .*\.noderc\.noexists\.test\.js/,
),
);
expect(result.stderrMonitor).not.toHaveBeenCalled();
},
TIMEOUT,
);

it(
'returns an exit code of 0 when passed a config file with no export',
async () => {
const result = await rrepl(['-c', '.noderc.nofunc.test.js']);
expect(result.errs).toHaveLength(0);
expect(result).toHaveProperty('signal', null);
expect(result).toHaveProperty('code', 0);
expect(result.stderrMonitor).not.toHaveBeenCalled();
},
TIMEOUT,
);
it('returns an exit code of 0', async () => {
expect.assertions(4);
const result = await rrepl(['-c', '.noderc.test.js']);
expect(result.errs).toHaveLength(0);
expect(result).toHaveProperty('signal', null);
expect(result).toHaveProperty('code', 0);
expect(result.stderrMonitor).not.toHaveBeenCalled();
});

it('returns an exit code of 0 and logs debug information in verbose mode', async () => {
expect.assertions(6);
const result = await rrepl(['-c', '.noderc.test.js', '-v']);
expect(result.errs).toHaveLength(0);
expect(result).toHaveProperty('signal', null);
expect(result).toHaveProperty('code', 0);
expect(result.stdoutMonitor).toHaveBeenCalledWith(
expect.stringMatching(
/\[DEBUG\] Configuring history at .*\.node_repl_history/,
),
);
expect(result.stdoutMonitor).toHaveBeenCalledWith(
expect.stringMatching(
/\[DEBUG\] Using configuration at .*\.noderc\.test\.js/,
),
);
expect(result.stderrMonitor).not.toHaveBeenCalled();
});

it('returns an exit code of 0 and skips history setup in verbose mode', async () => {
expect.assertions(5);
const result = await rrepl(['-c', '.noderc.test.js', '-v'], {
NODE_REPL_HISTORY: '',
});
expect(result.errs).toHaveLength(0);
expect(result).toHaveProperty('signal', null);
expect(result).toHaveProperty('code', 0);
expect(result.stdoutMonitor).toHaveBeenCalledWith(
expect.stringContaining('[DEBUG] Skipping history setup'),
);
expect(result.stderrMonitor).not.toHaveBeenCalled();
});

it('returns an exit code of 0 when defaulting to ~/.noderc', async () => {
expect.assertions(4);
const result = await rrepl([], { NODE_REPL_MODE: 'strict' });
expect(result.errs).toHaveLength(0);
expect(result).toHaveProperty('signal', null);
expect(result).toHaveProperty('code', 0);
expect(result.stderrMonitor).not.toHaveBeenCalled();
});

it('returns an exit code of 0 when passed a bad config path', async () => {
expect.assertions(4);
const result = await rrepl(['-c', '.noderc.noexists.test.js']);
expect(result.errs).toHaveLength(0);
expect(result).toHaveProperty('signal', null);
expect(result).toHaveProperty('code', 0);
expect(result.stderrMonitor).not.toHaveBeenCalled();
});

it('returns an exit code of 0 and logs debug messages when passed a bad config path in verbose mode', async () => {
expect.assertions(5);
const result = await rrepl(['-c', '.noderc.noexists.test.js', '-v']);
expect(result.errs).toHaveLength(0);
expect(result).toHaveProperty('signal', null);
expect(result).toHaveProperty('code', 0);
expect(result.stdoutMonitor).toHaveBeenCalledWith(
expect.stringMatching(
/\[DEBUG\] No configuration found at .*\.noderc\.noexists\.test\.js/,
),
);
expect(result.stderrMonitor).not.toHaveBeenCalled();
});

it('returns an exit code of 0 when passed a config file with no export', async () => {
expect.assertions(4);
const result = await rrepl(['-c', '.noderc.nofunc.test.js']);
expect(result.errs).toHaveLength(0);
expect(result).toHaveProperty('signal', null);
expect(result).toHaveProperty('code', 0);
expect(result.stderrMonitor).not.toHaveBeenCalled();
});

it.each(['.noderc.throws.test.js', '.noderc.throws.nofunc.test.js'])(
'returns an exit code of 1 when the config file throws an error (%s)',
async (filename) => {
expect.assertions(4);
const result = await rrepl(['-c', filename]);
expect(result.errs).toHaveLength(0);
expect(result).toHaveProperty('signal', null);
expect(result).toHaveProperty('code', 1);

expect(result.stderrMonitor).toHaveBeenCalledWith(
expect.stringContaining(
'An error occurred while loading configuration at',
),
);
},
TIMEOUT,
);

itif(platform() !== 'win32')(
it.if(platform() !== 'win32')(
'warns with an error when setting up history fails',
async () => {
const tmpFile = await file({
mode: 0o0200,
prefix: '.node_repl_history_',
});
const result = await rrepl(['-c', '.noderc.test.js'], {
NODE_REPL_HISTORY: tmpFile.path,
});
expect(result).toHaveProperty('signal', null);
expect(result.errs).toHaveLength(0);
// expect(result).toHaveProperty('code', 0); FIXME
expect(result.stdoutMonitor).toHaveBeenCalledWith(
expect.stringContaining('REPL session history will not be persisted'),
expect.assertions(3);
return withFile(
async ({ path }) => {
const result = await rrepl(['-c', '.noderc.test.js'], {
NODE_REPL_HISTORY: path,
});
expect(result).toHaveProperty('signal', null);
expect(result.errs).toHaveLength(0);
// expect(result).toHaveProperty('code', 0); FIXME
expect(result.stdoutMonitor).toHaveBeenCalledWith(
expect.stringContaining('REPL session history will not be persisted'),
);
},
{
mode: 0o0200,
prefix: '.node_repl_history_',
},
);

return tmpFile.cleanup();
},
TIMEOUT,
);
2 changes: 1 addition & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { version } from '../package.json';
repl.on('exit', () => {
process.exit(0);
});
} catch (err) {
} catch (err: any) {
// istanbul ignore if
if (!err.logged) console.error(err);
process.exit(1);
Expand Down
Loading

0 comments on commit 2d84ac4

Please sign in to comment.