New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

create-test-app

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

create-test-app

A scaffolding CLI to make your project tested by Jest and with coverage enabled.

  • 3.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
13
Maintainers
1
Weekly downloads
 
Created
Source

Welcome to create-test-app 👋

Armed your project with Jest.

A opinionated scaffolding CLI to make your project tested by Jest and with coverage enabled.

Why

Because configure Jest and set coverage is tedious 🤕.

Just with one line cmd 🚀, everything is configured for U ❤️!

Use

For TypeScript project:

npx create-test-app --type ts

For JavaScript project:

npx create-test-app

DONE!

Files to be modified or created.

  1. package.json
  2. jest.config.js
  3. babel.config.js
  4. test/: auto generate test
  5. won't modify tsconfig.json but auto mapping paths to jest's moduleNameMapper

Advanced

set coverage to 50 and and add jest transform.

npx create-test-app --type ts --coverage 50 --transform="{ vue: 'vue-jest' }"
  'transform': {
+    '^.+\\.(vue)$': 'vue-jest',
  },

How it works

Automatically armed your project with jest. You can do it manually if you don't trust this CLI.

TS

For TS. It will go through the steps:

1. Install
npm i -D jest typescript ts-jest @types/jest
2. Initialize jest.config.js
npx ts-jest config:init
3. Collect Coverage
npx jest --init

jest.config.js

module.exports = {
   preset: 'ts-jest',
   testEnvironment: "node",

+  coverageDirectory: "coverage",
+  coverageProvider: "v8",
+  coverageThreshold: {
    "global": {
      "branches": 100,
      "functions": 100,
      "lines": 100,
      "statements": 100
    }
  },
}

package.json

   "scripts": {
     "build": "tsc --declaration",
     "preversion": "npm run build",
     "postversion": "npm publish && git push && git push --tags",
-    "test": "jest"
+    "test": "jest --coverage"
   },

.gitignore

+coverage/
4. Write tests
md test && cd test && touch lite-lodash.test.ts
// lite-lodash.test.js
import { isPromise } from '../src/lib/lite-lodash'

describe('isPromise', () => {
  it('`Promise.resolve()` should be a promise', () => {
    const input = Promise.resolve();
    const actual = isPromise(input);
    const expected = true;

    expect(actual).toEqual(expected);
  });

  it('`new Promise` should be a promise', () => {
    const input = new Promise(() => {});
    const actual = isPromise(input);
    const expected = true;

    expect(actual).toEqual(expected);
  });
});

from Jest 运行 TypeScript 单测并增加覆盖率.

JS

1. Install
npm i -D jest @types/jest

All the same without npx ts-jest config:init.

Run tests

npm test

TODO

  • UX improvement: auto check whether it is a TS project

Author

👤 legend80s

Show your support

Give a ⭐️ if this project helped you!


This README was generated with ❤️ by readme-md-generator.

Powered by pnpm.

Keywords

FAQs

Package last updated on 30 Jul 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc