npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

create-test-app

v3.0.4

Published

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

Downloads

69

Readme

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.