Skip to content

Commit

Permalink
chore(): add tests configuration and packages updates
Browse files Browse the repository at this point in the history
  • Loading branch information
leandrosimoes committed Jan 23, 2024
1 parent fb357a6 commit 7a4f077
Show file tree
Hide file tree
Showing 23 changed files with 15,977 additions and 7,503 deletions.
1 change: 1 addition & 0 deletions .codacy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ exclude_paths:
- '.vscode/**'
- '.husky/**'
- '**.md'
- '**.json'
5 changes: 4 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
node_modules/
.vscode/
*.md
*.config.*
*.config.*
dist/
**/*/*.spec.*
jest.config.js
16 changes: 12 additions & 4 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
"tsconfigRootDir": "."
},
"rules": {
"comma-dangle": [
"error",
"always-multiline"
],
"comma-dangle": "off",
"unused-imports/no-unused-imports": "error",
"unused-imports/no-unused-vars": [
"warn",
Expand Down Expand Up @@ -46,6 +43,17 @@
"ignoreCase": true
}
}
],
"prettier/prettier": [
"error",
{
"trailingComma": "es5",
"tabWidth": 4,
"semi": false,
"singleQuote": true,
"endOfLine": "auto"
}

]
},
"plugins": [
Expand Down
2 changes: 1 addition & 1 deletion .husky/pre-commit → .husky/pre-push
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

yarn lint
yarn test
40 changes: 40 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/index.ts",
"runtimeArgs": [
"-r",
"ts-node/register",
"-r",
"tsconfig-paths/register"
],
"preLaunchTask": "tsc: build - tsconfig.json",
"outFiles": [
"${workspaceFolder}/**/*.js"
]
},
{
"type": "node",
"request": "launch",
"name": "Debug Tests: Current File",
"env": { "NODE_OPTIONS": "--experimental-vm-modules" },
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": ["${fileBasenameNoExtension}", "--config", "jest.config.js"],
"preLaunchTask": "tsc: build - tsconfig.test.json",
"console": "integratedTerminal",
"windows": {
"program": "${workspaceFolder}/node_modules/jest/bin/jest"
}
}
]
}
8 changes: 1 addition & 7 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
{
"github.copilot.enable": {
"*": false,
"yaml": false,
"plaintext": false,
"markdown": false
},
"typescript.tsdk": "./node_modules/typescript/lib",
"editor.formatOnSave": false,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
},
}
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@ Just execute the command `yarn start`
* [Ora](https://github.com/sindresorhus/ora/tree/v5.4.1)
* [Inquirer](https://github.com/SBoudrias/Inquirer.js/tree/inquirer%408.2.3)
* [Yargs](https://github.com/yargs/yargs/tree/v17.5.1)
* [ESM](https://nodejs.org/api/esm.html)

## Dev Environment

* [Typescript](https://github.com/microsoft/TypeScript/tree/v4.7.4)
* [ESlint](https://github.com/eslint/eslint/tree/v8.19.0)
* [Prettier](https://github.com/prettier/prettier/tree/2.7.1)
* [Husky](https://typicode.github.io/husky/#/)
* [Commit Lint](https://commitlint.js.org/#/)
* [Commit Lint](https://commitlint.js.org/#/)

## Common problems testing Typescript + ESM + Jest

- See https://dev.to/logto/migrate-a-60k-loc-typescript-nodejs-repo-to-esm-and-testing-become-4x-faster-22-4a4k
30 changes: 14 additions & 16 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,39 @@
#!/usr/bin/env node

import { questions, args } from './src/services/index.js'
import { showSpinner, stopSpinner, showMessage } from './src/utils/index.js'

import { questions, args, logging } from './src/apis/index.js'
;(async () => {
const commandArgs = args.parseArgs(process.argv).parseSync()

const answers = await questions.start()
const isHappy = await questions.areYouHappy()

await showSpinner({ text: 'Starting process ...', color: 'blue' })
await logging.showSpinner({ text: 'Starting process ...', color: 'blue' })

if (commandArgs.debug) {
await showMessage({
await logging.showMessage({
text: 'Showing a more detailed log',
color: 'yellow',
})
await showMessage({
text: JSON.stringify(answers, null, 2),
})
await logging.showMessage({
text: isHappy ? 'You are happy!' : 'You are not happy!',
color: 'yellow',
})
}

if (answers.isHappy) {
await showMessage({
if (isHappy) {
await logging.showMessage({
text: "If you are happy, I'm happy too!",
color: 'green',
clear: true,
})
} else {
await showMessage({
text: "Sorry to hear that!",
await logging.showMessage({
text: 'Sorry to hear that!',
color: 'red',
clear: true,
})
})
}

await showSpinner({ text: 'Finishing process...', color: 'green' })
await logging.showSpinner({ text: 'Finishing process...', color: 'green' })

stopSpinner()
logging.stopSpinner()
})()
4 changes: 4 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/** @type {import('jest').Config} */
export default {
roots: ['./dist'], // Point to the build directory
}
Loading

0 comments on commit 7a4f077

Please sign in to comment.