Coder Social home page Coder Social logo

e2edce's Introduction

About

Deadcode elimination via running end-to-end tests.

Sample project: DCE for threejs

Install

npm i -D ycw/e2edce

Usage

First, create a configuration file in project root

Then, config package.json

{ 
  "scripts": {
    "build": "e2edce e2edce.config.js"
  }
}

Finally, run npm run build to build artifacts

  • index.build.js (min)
  • index.build.js.gz (min + gzipped)

Configuration File

e2edce.config.js

export default {
  // --- required ---
  configs: [ // array of configs
    {
      // --- required ---
      input: 'src/index.js', // path to entry
      output: 'index.build.js', // path to output file
      test: 'e2e/test.js', // path to test file 
      // --- optional ---
      compress: true, 
      mangle: true,
      beautify: false, // with indentation?
      debug: false, // create a debug build?
      port: 8081, // dev server port
      headless: true, // run tests in headless browser?
      visitor: undefined, // transform sources 
    }
  ],
  // --- optional ---
  setup: async() => {}, // run once before processing
  teardown: async() => {}, // run once after processing
  resolve: async() => {}, // custom module resolution
}

Test File

e2e/test.js

Export a async fn or an object

export default async (page) => { // e2e test
  await page.goto('http://localhost:8081', { waitUntil: 'networkidle' })
}
export default {
  // --- required ---
  test: async () => { // e2e test
    await page.goto('http://localhost:8081', { waitUntil: 'networkidle' })
  },
  // --- optional ---
  inject: () => {}
}
  • page is a https://playwright.dev/docs/api/class-page

  • inject, a fn to be injected at the end of input module

    We could add mocks inside inject() to directly cover certain code branches instead of writing complex e2e tests inside test()

e2edce's People

Contributors

ycw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.