Add runtime test that TypeScript imports are working (#1473)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
* Add runtime test that TypeScript imports are working * Add test of default export, have not deleted it yet!
authored by John Gee · committed by GitHub · parent 4aaaa9d · Browse files · 6 files·+138 added−36 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
6 files+138 added−36 removed
- tests:+77 added−32 removed
- other:+61 added−4 removed
Provenance
- Commit
c119028- Tree
fe7041f- Author
John Gee <john@ruru.gen.nz>- Committer
GitHub <noreply@github.com>- Parent
4aaaa9d
6 files changed+138 added−36 removed
added:tests/esm-imports-test.mjs+33 added
123456789101112131415161718192021222324252627282930313233import { program, Command, Option, CommanderError, InvalidOptionArgumentError, Help, createCommand } from '../esm.mjs';
// Do some simple checks that expected imports are available at runtime.// Run using `npm run test-esm`.// Similar tests to test-imports.test.ts
function check(condition, explanation) { if (!condition) { console.log(`Failed assertion: ${explanation}`); process.exit(2); }}
function checkClass(obj, name) { console.log(`Checking ${name}`); check(typeof obj === 'object', `new ${name}() produces object`); check(obj.constructor.name === name, `object constructor is ${name}`);}
console.log('Checking program');check(typeof program === 'object', 'program is object');check(program.constructor.name === 'Command', 'program is class Command');
checkClass(new Command(), 'Command');checkClass(new Option('-e, --example'), 'Option');checkClass(new CommanderError(1, 'code', 'failed'), 'CommanderError');checkClass(new InvalidOptionArgumentError('failed'), 'InvalidOptionArgumentError');checkClass(new Help(), 'Help');
console.log('Checking createCommand');check(typeof createCommand === 'function', 'createCommand is function');
console.log('No problems');deleted:tests/esm-test.mjs-32 removed
1234567891011121314151617181920212223242526272829303132import { program, Command, Option, CommanderError, InvalidOptionArgumentError, Help, createCommand } from '../esm.mjs';
// Do some simple checks that expected imports are available.// Run using `npm run test-esm`.
function check(condition, explanation) { if (!condition) { console.log(`Failed assertion: ${explanation}`); process.exit(2); }}
function checkClass(obj, name) { console.log(`Checking ${name}`); check(typeof obj === 'object', `new ${name}() produces object`); check(obj.constructor.name === name, `object constructor is ${name}`);}
console.log('Checking program');check(typeof program === 'object', 'program is object');check(program.constructor.name === 'Command', 'program is class Command');
checkClass(new Command(), 'Command');checkClass(new Option('-e, --example'), 'Option');checkClass(new CommanderError(1, 'code', 'failed'), 'CommanderError');checkClass(new InvalidOptionArgumentError('failed'), 'InvalidOptionArgumentError');checkClass(new Help(), 'Help');
console.log('Checking createCommand');check(typeof createCommand === 'function', 'createCommand is function');
console.log('No problems');added:tests/ts-imports.test.ts+44 added
1234567891011121314151617181920212223242526272829303132333435363738394041424344import { program, Command, Option, CommanderError, InvalidOptionArgumentError, Help, createCommand } from '../';
import * as commander from '../';
// Do some simple checks that expected imports are available at runtime.// Similar tests to esm-imports-test.js
// eslint-disable-next-line @typescript-eslint/ban-typesfunction checkClass(obj: object, name: string) { expect(typeof obj).toEqual('object'); expect(obj.constructor.name).toEqual(name);}
test('legacy default export of global Command', () => { checkClass(commander, 'Command');});
test('program', () => { checkClass(program, 'Command');});
test('createCommand', () => { checkClass(createCommand(), 'Command');});
test('Command', () => { checkClass(new Command('name'), 'Command');});
test('Option', () => { checkClass(new Option('-e, --example', 'description'), 'Option');});
test('CommanderError', () => { checkClass(new CommanderError(1, 'code', 'failed'), 'CommanderError');});
test('InvalidOptionArgumentError', () => { checkClass(new InvalidOptionArgumentError('failed'), 'InvalidOptionArgumentError');});
test('Help', () => { checkClass(new Help(), 'Help');});modified:package-lock.json+48 added
1523 unmodified lines1524 "resolved": "https://registry.npmjs.org/browser-process-hrtime/-/browser-process-hrtime-1.0.0.tgz",1525 "integrity": "sha512-9o5UecI3GhkpM6DrXr69PblIuWxPKk9Y0jHBRhdocZ2y7YECBFCsHm79Pr3OyR2AvjhDkabFJaDJMYRazHgsow==",1526 "dev": true1527 },1528+ "bs-logger": {1529+ "version": "0.2.6",1530+ "resolved": "https://registry.npmjs.org/bs-logger/-/bs-logger-0.2.6.tgz",1531+ "integrity": "sha512-pd8DCoxmbgc7hyPKOvxtqNcjYoOsABPQdcCUjGp3d42VR2CX1ORhk2A87oqqu5R1kk+76nsxZupkmyd+MVtCog==",1532+ "dev": true,1533+ "requires": {1534+ "fast-json-stable-stringify": "2.x"1535+ }1536+ },1537 "bser": {1538 "version": "2.1.1",1539 "resolved": "https://registry.npmjs.org/bser/-/bser-2.1.1.tgz",1540 "integrity": "sha512-gQxTNE/GAfIIrmHLUE3oJyp5FO6HRBfhjnw4/wMmA63ZGDJnWBmgY/lyQBpnDUkGmAhbSe39tx2d/iTOAfglwQ==",3096 unmodified lines4637 "dev": true4638 }4639 }4640 },4641+ "make-error": {4642+ "version": "1.3.6",4643+ "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz",4644+ "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==",4645+ "dev": true4646+ },4647 "makeerror": {4648 "version": "1.0.11",4649 "resolved": "https://registry.npmjs.org/makeerror/-/makeerror-1.0.11.tgz",4650 "integrity": "sha1-4BpckQnyr3lmDk6LlYd5AYT1qWw=",2170 unmodified lines6821 "resolved": "https://registry.npmjs.org/trim-newlines/-/trim-newlines-3.0.0.tgz",6822 "integrity": "sha512-C4+gOpvmxaSMKuEf9Qc134F1ZuOHVXKRbtEflf4NTtuuJDEIJ9p5PXsalL8SkeRw+qit1Mo+yuvMPAKwWg/1hA==",6823 "dev": true6824 },6825+ "ts-jest": {6826+ "version": "26.5.1",6827+ "resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-26.5.1.tgz",6828+ "integrity": "sha512-G7Rmo3OJMvlqE79amJX8VJKDiRcd7/r61wh9fnvvG8cAjhA9edklGw/dCxRSQmfZ/z8NDums5srSVgwZos1qfg==",6829+ "dev": true,6830+ "requires": {6831+ "@types/jest": "26.x",6832+ "bs-logger": "0.x",6833+ "buffer-from": "1.x",6834+ "fast-json-stable-stringify": "2.x",6835+ "jest-util": "^26.1.0",6836+ "json5": "2.x",6837+ "lodash": "4.x",6838+ "make-error": "1.x",6839+ "mkdirp": "1.x",6840+ "semver": "7.x",6841+ "yargs-parser": "20.x"6842+ },6843+ "dependencies": {6844+ "mkdirp": {6845+ "version": "1.0.4",6846+ "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz",6847+ "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==",6848+ "dev": true6849+ },6850+ "yargs-parser": {6851+ "version": "20.2.5",6852+ "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-20.2.5.tgz",6853+ "integrity": "sha512-jYRGS3zWy20NtDtK2kBgo/TlAoy5YUuhD9/LZ7z7W4j1Fdw2cqD0xEEclf8fxc8xjD6X5Qr+qQQwCEsP8iRiYg==",6854+ "dev": true6855+ }6856+ }6857+ },6858 "tsconfig-paths": {6859 "version": "3.9.0",6860 "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-3.9.0.tgz",6861 "integrity": "sha512-dRcuzokWhajtZWkQsDVKbWyY+jgcLC5sqJhg2PSgf4ZkH2aHPvaOY8YWGhmjb68b5qqTfasSsDO9k7RUiEmZAw==",476 unmodified linesmodified:package.json+11 added-3 removed
18 unmodified lines1920212223232425252627282914 unmodified lines44454647484950515253545355565758596061626364656618 unmodified lines "url": "https://github.com/tj/commander.js.git" }, "scripts": { "lint": "eslint index.js esm.mjs \"tests/**/*.js\"", "typescript-lint": "eslint typings/*.ts", "typescript-lint": "eslint typings/*.ts tests/*.ts", "test": "jest && npm run test-typings", "test-esm": "node --experimental-modules ./tests/esm-test.mjs", "test-esm": "node --experimental-modules ./tests/esm-imports-test.mjs", "test-typings": "tsd", "typescript-checkJS": "tsc --allowJS --checkJS index.js --noEmit", "test-all": "npm run test && npm run lint && npm run typescript-lint && npm run typescript-checkJS && npm run test-esm" },14 unmodified lines "eslint-config-standard": "^16.0.2", "eslint-plugin-jest": "^24.1.3", "jest": "^26.6.3", "standard": "^16.0.3", "ts-jest": "^26.5.1", "tsd": "^0.14.0", "typescript": "^4.1.2" }, "types": "typings/index.d.ts", "jest": { "testEnvironment": "node", "collectCoverage": true "collectCoverage": true, "transform": { "^.+\\.tsx?$": "ts-jest" }, "testPathIgnorePatterns": [ "/node_modules/" ] }, "engines": { "node": ">= 10" }}modified:tsconfig.json+2 added-1 removed
6 unmodified lines78910111112131415162 unmodified lines6 unmodified lines "noImplicitAny": true, "noImplicitThis": true, "strictNullChecks": true, "types": [ "node" "node", "jest" ], "noEmit": true, "forceConsistentCasingInFileNames": true },2 unmodified lines