Skip to content

Commit

Permalink
TODO: Failing test that should pass
Browse files Browse the repository at this point in the history
  • Loading branch information
SBoudrias committed Mar 4, 2024
1 parent ac144ba commit 1e81710
Show file tree
Hide file tree
Showing 16 changed files with 219 additions and 112 deletions.
1 change: 0 additions & 1 deletion .eslintignore
Expand Up @@ -4,4 +4,3 @@ coverage
dist
packages/*/node_modules
packages/*/__snapshots__
*.test-d.ts
24 changes: 23 additions & 1 deletion .eslintrc.json
Expand Up @@ -64,7 +64,11 @@
}
},
{
"files": ["packages/inquirer/test/**", "packages/**/*.test.*"],
"files": [
"packages/inquirer/test/**",
"packages/**/*.test.*",
"canary/**/*.test.*"
],
"rules": {
"n/no-extraneous-import": [
"error",
Expand All @@ -79,6 +83,24 @@
}
]
}
},
{
"files": ["packages/**/*.test-d.*", "canary/**/*.test-d.*"],
"rules": {
"@typescript-eslint/no-unused-vars": "off",
"n/no-extraneous-import": [
"error",
{
"allowModules": ["vitest"]
}
],
"n/no-extraneous-require": [
"error",
{
"allowModules": ["vitest"]
}
]
}
}
]
}
14 changes: 14 additions & 0 deletions .github/workflows/main.yml
Expand Up @@ -64,3 +64,17 @@ jobs:
run: yarn turbo tsc
- name: Integration tests
run: yarn node --test integration/

TypesTest:
name: Typing validation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: corepack enable
- uses: actions/setup-node@v4
with:
node-version: 20
cache: 'yarn'
- run: yarn install --immutable --immutable-cache
- name: Typescript
run: yarn tsc --project tsconfig.test.json
File renamed without changes.
4 changes: 2 additions & 2 deletions packages/canary/demo.ts → canary/inquirer/demo.mts
@@ -1,4 +1,4 @@
import inquirer from './src/index.js';
import inquirer from './src/index.mjs';

const answers = await inquirer.prompt([
{
Expand All @@ -18,7 +18,7 @@ const answers = await inquirer.prompt([
{
type: 'input',
name: 'last_name',
when: (answers) => Boolean(answers.ask_last_name),
when: (currentAnswers) => Boolean(currentAnswers.ask_last_name),
message: "What's your last name",
},
{
Expand Down
92 changes: 92 additions & 0 deletions canary/inquirer/package.json
@@ -0,0 +1,92 @@
{
"name": "@inquirer/canary",
"version": "0.0.0",
"description": "Inquirer input text prompt",
"main": "./dist/cjs/index.js",
"typings": "./dist/cjs/types/index.d.ts",
"files": [
"dist/**/*"
],
"repository": {
"type": "git",
"url": "https://github.com/SBoudrias/Inquirer.js.git"
},
"keywords": [
"answer",
"answers",
"ask",
"base",
"cli",
"command",
"command-line",
"confirm",
"enquirer",
"generate",
"generator",
"hyper",
"input",
"inquire",
"inquirer",
"interface",
"iterm",
"javascript",
"menu",
"node",
"nodejs",
"prompt",
"promptly",
"prompts",
"question",
"readline",
"scaffold",
"scaffolder",
"scaffolding",
"stdin",
"stdout",
"terminal",
"tty",
"ui",
"yeoman",
"yo",
"zsh"
],
"author": "Simon Boudrias <admin@simonboudrias.com>",
"license": "MIT",
"homepage": "https://github.com/SBoudrias/Inquirer.js",
"dependencies": {
"@inquirer/checkbox": "^2.1.0",
"@inquirer/confirm": "^3.0.0",
"@inquirer/core": "^7.0.0",
"@inquirer/editor": "^2.0.0",
"@inquirer/expand": "^2.0.0",
"@inquirer/input": "^2.0.0",
"@inquirer/password": "^2.0.0",
"@inquirer/rawlist": "^2.0.0",
"@inquirer/select": "^2.0.0",
"@inquirer/type": "^1.0.5",
"lodash": "^4.17.21"
},
"scripts": {
"tsc": "yarn run tsc:esm && yarn run tsc:cjs",
"tsc:esm": "rm -rf dist/esm && tsc -p ./tsconfig.json",
"tsc:cjs": "rm -rf dist/cjs && tsc -p ./tsconfig.cjs.json && node ../../tools/fix-ext.mjs"
},
"publishConfig": {
"access": "public"
},
"engines": {
"node": ">=18"
},
"exports": {
".": {
"import": {
"types": "./dist/esm/types/index.d.mts",
"default": "./dist/esm/index.mjs"
},
"require": {
"types": "./dist/cjs/types/index.d.ts",
"default": "./dist/cjs/index.js"
}
}
}
}
23 changes: 7 additions & 16 deletions packages/canary/src/index.ts → canary/inquirer/src/index.mts
Expand Up @@ -23,13 +23,9 @@ function createPromptModule() {
select,
};

type GetPrompt<U extends keyof typeof promptStore> = typeof promptStore[U];
type GetAnswerType<U extends keyof typeof promptStore> = GetPrompt<U> extends Prompt<
infer Answer,
any
>
? Answer
: never;
type GetPrompt<U extends keyof typeof promptStore> = (typeof promptStore)[U];
type GetAnswerType<U extends keyof typeof promptStore> =
GetPrompt<U> extends Prompt<infer Answer, any> ? Answer : never;
type GetPromptFnConfig<U> = U extends any
? U extends Prompt<any, infer Config>
? Config
Expand All @@ -46,7 +42,7 @@ function createPromptModule() {
when?: (answers: Answers) => boolean | Promise<boolean>;
filter?: (
answer: GetAnswerType<U>,
answers: Answers
answers: Answers,
) => AsyncValue<GetAnswerType<U>>;
}
: never;
Expand All @@ -58,7 +54,7 @@ function createPromptModule() {
config:
| PromptNameToFullConfig<keyof typeof promptStore>
| PromptNameToFullConfig<keyof typeof promptStore>[],
context?: Context
context?: Context,
) {
const answers: Answers = {};
const promptSeries = Array.isArray(config) ? config : [config];
Expand Down Expand Up @@ -96,20 +92,15 @@ function createPromptModule() {
registerPrompt('select', select);
}

prompt.prompt = prompt;
prompt.registerPrompt = registerPrompt;
prompt.createPromptModule = createPromptModule;
prompt.restoreDefaultPrompts = restoreDefaultPrompts;

return prompt;
}

const prompt = createPromptModule();
const inquirer = {
prompt,
registerPrompt: prompt.registerPrompt,
createPromptModule: prompt.createPromptModule,
restoreDefaultPrompts: prompt.restoreDefaultPrompts,
};
const inquirer = createPromptModule();
export default inquirer;

export {
Expand Down
11 changes: 11 additions & 0 deletions canary/inquirer/tsconfig.cjs.json
@@ -0,0 +1,11 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"lib": ["ES6"],
"target": "es6",
"module": "commonjs",
"moduleResolution": "node10",
"outDir": "dist/cjs",
"declarationDir": "dist/cjs/types"
}
}
13 changes: 13 additions & 0 deletions canary/inquirer/tsconfig.json
@@ -0,0 +1,13 @@
{
"extends": "../../tsconfig.json",
"include": ["./src"],
"exclude": ["**/*.test.mts"],
"compilerOptions": {
"lib": ["ESNext"],
"target": "es2022",
"module": "NodeNext",
"moduleResolution": "nodenext",
"outDir": "dist/esm",
"declarationDir": "dist/esm/types"
}
}
@@ -1,9 +1,10 @@
import inquirer from './src/index.js';
import { describe, it, expect } from 'vitest';
import inquirer from './src/index.mjs';

describe('Library types work properly', () => {
it('input', () => {
expect(() => {
return inquirer.prompt([
expect(() =>
inquirer.prompt([
{
type: 'input',
name: 'first_name',
Expand Down Expand Up @@ -56,13 +57,13 @@ describe('Library types work properly', () => {
return 1;
},
},
]);
}).toBeInstanceOf(Function);
]),
).toBeInstanceOf(Function);
});

it('select', () => {
expect(() => {
return inquirer.prompt([
expect(() =>
inquirer.prompt([
{
type: 'select',
name: 'ask_last_name',
Expand All @@ -78,6 +79,28 @@ describe('Library types work properly', () => {
name: 'ask_last_name',
message: 'Are you willing to share your last name',
},
]),
).toBeInstanceOf(Function);
});

it('register prompt', () => {
expect(() => {
inquirer.prompt([
{
/* @ts-expect-error: this prompt doesn't exist */
type: 'unknown-prompt',
name: 'ask_last_name',
message: 'Are you willing to share your last name',
},
]);

inquirer.registerPrompt('unknown-prompt', {} as any);
inquirer.prompt([
{
type: 'unknown-prompt',
name: 'ask_last_name',
message: 'Are you willing to share your last name',
},
]);
}).toBeInstanceOf(Function);
});
Expand Down
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -72,7 +72,8 @@
},
"workspaces": [
"packages/*",
"integration/*"
"integration/*",
"canary/*"
],
"scripts": {
"prepare": "husky && turbo tsc",
Expand Down
74 changes: 0 additions & 74 deletions packages/canary/package.json

This file was deleted.

0 comments on commit 1e81710

Please sign in to comment.