blitz-js / legacy-framework

MIT License
3 stars 2 forks source link

`blitz new` missing the test packages #397

Closed ghost closed 2 years ago

ghost commented 2 years ago

What is the problem?

Blitz does not come with testing packages like described https://blitzjs.com/docs/testing

Paste all your error logs here:

Paste all relevant code snippets here:

✔ Retrieving the freshest of dependencies
✔ Resolving packages
✔ Fetching packages
✔ Linking dependencies
✔ Building fresh packages
✔ Initializing SQLite database
✔ Committing your app

Your new Blitz app is ready! Next steps:

   1. cd TestingForTest
   2. blitz dev

 ─────────────────
$ cd TestingForTest 
~/Desktop/TestingForTest 
$ cat package.json                                                    
{
  "name": "TestingForTest",
  "version": "1.0.0",
  "scripts": {
    "dev": "blitz dev",
    "build": "blitz build",
    "start": "blitz start",
    "studio": "blitz prisma studio",
    "lint": "eslint --ignore-path .gitignore --ext .js,.ts,.tsx .",
    "test": "jest",
    "test:watch": "jest --watch",
    "prepare": "husky install"
  },
  "prisma": {
    "schema": "db/schema.prisma"
  },
  "prettier": {
    "semi": false,
    "printWidth": 100
  },
  "lint-staged": {
    "*.{js,ts,tsx}": [
      "eslint --fix"
    ]
  },
  "dependencies": {
    "@prisma/client": "3.4.1",
    "blitz": "0.42.4",
    "react-dom": "18.0.0-alpha-5ca4b0433-20211020",
    "react": "18.0.0-alpha-5ca4b0433-20211020",
    "zod": "3.11.6",
    "final-form": "4.20.4",
    "react-final-form": "6.5.7"
  },
  "devDependencies": {
    "@types/preview-email": "2.0.1",
    "@types/react": "17.0.34",
    "eslint": "7.32.0",
    "husky": "7.0.4",
    "lint-staged": "11.2.6",
    "prettier-plugin-prisma": "3.4.1",
    "prettier": "2.4.1",
    "pretty-quick": "3.1.1",
    "preview-email": "3.0.5",
    "prisma": "3.4.1",
    "typescript": "~4.4"
  },
  "private": true
}

What are detailed steps to reproduce this?

  1. $ blitz new TestingForTestPackages
  2. Typescript
  3. yarn
  4. yes yes
  5. cd TestingForTestPackages
  6. cat package.json

Run blitz -v and paste the output here:

$ blitz -v                
macOS Big Sur | darwin-x64 | Node: v12.19.0

blitz: 0.42.4 (global)
blitz: 0.42.4 (local)

  Package manager: yarn 
  System:
    OS: macOS 11.4
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 224.59 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 12.19.0 - /usr/local/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 6.14.8 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  npmPackages:
    @prisma/client: 3.4.1 => 3.4.1 
    blitz: 0.42.4 => 0.42.4 
    prisma: 3.4.1 => 3.4.1 
    react: 18.0.0-alpha-5ca4b0433-20211020 => 18.0.0-alpha-5ca4b0433-20211020 
    react-dom: 18.0.0-alpha-5ca4b0433-20211020 => 18.0.0-alpha-5ca4b0433-20211020 
    typescript: ~4.4 => 4.4.4 

Please include below any other applicable logs and screenshots that show your problem:

No response

ghost commented 2 years ago

Became aware of it when running yarn tsc and saw all the related errors

tried to add them manually

package.json

{
  "name": "HelloWord",
  "version": "1.0.0",
  "scripts": {
    "dev": "blitz dev",
    "build": "blitz build",
    "start": "blitz start",
    "studio": "blitz prisma studio",
    "lint": "eslint --ignore-path .gitignore --ext .js,.ts,.tsx .",
    "test": "jest",
    "test:watch": "jest --watch",
    "prepare": "husky install"
  },
  "prisma": {
    "schema": "db/schema.prisma"
  },
  "prettier": {
    "semi": false,
    "printWidth": 100
  },
  "lint-staged": {
    "*.{js,ts,tsx}": [
      "eslint --fix"
    ]
  },
  "dependencies": {
    "@prisma/client": "3.4.1",
    "blitz": "0.42.4",
    "final-form": "4.20.4",
    "react": "18.0.0-alpha-5ca4b0433-20211020",
    "react-dom": "18.0.0-alpha-5ca4b0433-20211020",
    "react-final-form": "6.5.7",
    "zod": "3.11.6"
  },
  "devDependencies": {
    "@testing-library/jest-dom": "5.15.0",
    "@testing-library/react": "12.1.2",
    "@testing-library/react-hooks": "7.0.2",
    "@types/preview-email": "2.0.1",
    "@types/react": "17.0.34",
    "cypress": "8.7.0",
    "eslint": "7.32.0",
    "husky": "7.0.4",
    "jest": "27.3.1",
    "lint-staged": "11.2.6",
    "prettier": "2.4.1",
    "prettier-plugin-prisma": "3.4.1",
    "pretty-quick": "3.1.1",
    "preview-email": "3.0.5",
    "prisma": "3.4.1",
    "typescript": "~4.4"
  },
  "private": true
}

tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "baseUrl": "./",
    "allowJs": true,
    "skipLibCheck": true,
    "strict": false,
    "strictNullChecks": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "noUncheckedIndexedAccess": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true,
    "tsBuildInfoFile": ".tsbuildinfo",
    "types": ["cypress", "jest", "@testing-library/jest-dom"]
  },
  "exclude": ["node_modules", "**/*.e2e.ts"],
  "include": ["blitz-env.d.ts", "**/*.ts", "**/*.tsx"]
}

test/setup.ts

// This is the jest 'setupFilesAfterEnv' setup file
// It's a good place to set globals, add global before/after hooks, etc
import "@testing-library/jest-dom/extend-expect"

export {} // so TS doesn't complain

but typescript is still not detecting the extend-expect ? 🤷‍♂️

ghost commented 2 years ago

Extending the previous comment 👆

The jest packages are lacking but found that there was an issue with the way I installed cypress.

test/setup.js

// This is the jest 'setupFilesAfterEnv' setup file
// It's a good place to set globals, add global before/after hooks, etc
import "@testing-library/jest-dom/extend-expect"

export {} // so TS doesn't complain

(not sure if the blitz preset in the jest.config.ts should take care of it or this boilerplate file needs to be updated to this?)

tsconfig.json

{
  "compilerOptions": {
    ...
    "types": ["jest", "@testing-library/jest-dom"]
  },
  "exclude": ["node_modules", "**/*.e2e.ts", "**/*.spec.ts"],
  "include": ["blitz-env.d.ts", "**/*.ts", "**/*.tsx"]
}

(notice the addition of `"/*.spec.ts"** and that"cypress"` is not part of the types)

cypress/tsconfig.json

{
  "compilerOptions": {
    "types": ["cypress"]
  },
  "include": ["**/*.e2e.ts", "**/*.spec.ts"]
}

(would like to "extends": "../tsconfig.json" but it's giving me some error about No inputs were found in config file)

beerose commented 2 years ago

Regarding the test packages blitz dependency already has jest, and @testing-library/*. Can you paste errors you saw?

ghost commented 2 years ago

I have tried see if I can reproduce it by starting a new and repeating the steps and reverting the jest installs on my existing. I just can't reproduce the issue. 🤔

I apologise for any inconvenience it might have caused you.

beerose commented 2 years ago

There's no inconvenience! I'm glad the issue is solved. Feel free to reopen this issue or open a new one if you face any more problems :)