Code Monkey home page Code Monkey logo

knapsackpro / knapsack-pro-js Goto Github PK

View Code? Open in Web Editor NEW
3.0 5.0 0.0 5.02 MB

Run your 1-hour test suite in 2 minutes with optimal parallelisation on your existing CI infrastructure

Home Page: https://knapsackpro.com

License: MIT License

TypeScript 76.96% Shell 11.38% JavaScript 8.93% Dockerfile 0.34% HTML 1.55% CSS 0.84%
javascript parallelism testing testing-tools typescript knapsack-pro cypress jest parallelization test-automation cypress-io jest-plugin

knapsack-pro-js's Introduction

Knapsack Pro JS

Knapsack Pro

Speed up your tests

Run your 1-hour test suite in 2 minutes with optimal parallelisation on your existing CI infrastructure




Knapsack Pro wraps your current test runner(s) and works with your existing CI infrastructure to parallelize tests optimally:

  • Dynamically splits your tests based on up-to-date test execution data
  • Is designed from the ground up for CI and supports all of them
  • Tracks your CI builds to detect bottlenecks
  • Does not have access to your source code and collects minimal test data
  • Enables you to export historical metrics about your CI builds
  • Replaces local dependencies like Redis with an API and runs your tests regardless of network problems

Installation

See the docs to get started:

Contributing

Requirements

>= Node 18.13.0 LTS

You can use NVM to manage Node versions in development.

Setup

npm install
npm run build
# Need a second install to run:
#   - npx @knapsack-pro/jest
#   - npx @knapsack-pro/cypress
# See https://github.com/npm/cli/issues/4591#issuecomment-1111557730
npm install

Testing

npm run test:core:coverage
npm run test:jest
npm run test:cypress
npm run test:cra

You can find more example scripts in the nested packages/.

IDE (VSCode)

Install the following plugins:

In File > Preferences > Settings > Text Editor > Formatting, enable the Format On Save checkbox.

Publishing

Core

# merge PR and pull or edit code
# if new files that should be part of the released npm package were added, please ensure they are included in the `files` array in `package.json`
# update CHANGELOG to move *unreleased* into the proper *version*
npm version LEVEL -w packages/core
git add --all
git commit -m "chore: prepare release"
git tag @knapsack-pro/[email protected]
git push origin main --tags
cd packages/core
npm run build
npm adduser # sign in to npm
npm publish

Jest and/or Cypress

Replace PACKAGE with jest, or cypress. If core changed you'll need to update both.

# merge PR and pull or edit code
# if new files that should be part of the released npm package were added, please ensure they are included in the `files` array in `package.json`
# update CHANGELOG(s) to move *unreleased* into the proper *version*
npm version LEVEL -w packages/PACKAGE
npm install @knapsack-pro/core -w packages/jest
# make sure @knapsack-pro/core was updated in packages/jest/package.json (you can retry specifying the version [email protected])
npm install @knapsack-pro/core -w packages/cypress
# make sure @knapsack-pro/core was updated in packages/cypress/package.json (you can retry specifying the version [email protected])
git add --all
git commit -m "chore: prepare release"
git tag @knapsack-pro/[email protected] # can be multiple tags
git push origin main --tags
cd packages/PACKAGE
npm run build
npm adduser # sign in to npm
npm publish
npm install -D @knapsack-pro/jest -w packages/jest-example-test-suite
# make sure @knapsack-pro/jest was updated in packages/jest-example-test-suite/package.json (you can retry specifying the version [email protected])
npm run test:jest

npm install -D @knapsack-pro/cypress -w packages/cypress-example-test-suite
# make sure @knapsack-pro/cypress was updated in packages/cypress-example-test-suite/package.json
npm run test:cypress

# since create-react-app-example is not a workspace (for now)
cd packages/create-react-app-example
npm install -D @knapsack-pro/jest
# make sure @knapsack-pro/jest was updated in packages/create-react-app-example/package.json
npm run test:cra

git add --all
git commit -m "deps(examples): update @knapsack-pro"

Remember to update TestSuiteClientVersionChecker for the Knapsack Pro API repository.

Packages

Read the READMEs inside the nested packages/:

Legacy Repositories

Before merging the Knapsack Pro packages into this monorepo, each one was hosted in a separate repository:

knapsack-pro-js's People

Contributors

3v0k4 avatar andrcuns avatar arturt avatar dependabot[bot] avatar geoffharcourt avatar github-actions[bot] avatar haines avatar mattvague avatar pacyfik avatar rafaltrzop avatar renehernandez avatar shadre avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

knapsack-pro-js's Issues

Create react app example

Hi!
Trying to play with knapsack-pro/jest in the project that was bootstrapped by the create-react-app tool and encountered an issue that jest cannot parse my files. Seems like it cannot read jest config provided by CRA.
Would be nice if you can create an example project that uses clean CRA (ideally with typescript) + knapsack-pro. CRA has become a very convenient tool that react community use, it would be much appreciated to have at least a docs section regarding it.
Thanks in advance!

Use 0 seconds as execution time when a test file was not executed by test runner

This should help with edge case when test file cannot be executed by test runner and because of that we won't record timing of that test file.

Edge case could happen when:

  • test file is empty
  • test file has only pending tests
  • test file has syntax error

In such case, we could assume the test file has some default timing like 0.1s of 0 seconds.

Solution idea

We should improve this part of code:

// src/knapsack-pro-core.ts
        onSuccess(queueTestFiles).then(({ recordedTestFiles, isTestSuiteGreen }) => {
          // here we should take all tests from queueTestFiles and assume 0s of execution time for them
          // and merge them with recordedTestFiles.
          // In case recordedTestFiles has less test files than queueTestFiles then 
          // we would have 0s execution time for not executed test files by test runner
          // recordedTestFiles could have less tests when the test runner like Cypress/Jest won't be able to run it and it won't report the test file back to us
          this.recordedTestFiles = this.recordedTestFiles.concat(recordedTestFiles);
          this.isTestSuiteGreen = this.isTestSuiteGreen && isTestSuiteGreen;

          this.fetchTestsFromQueue(false, onSuccess, onFailure);
        });

Related

A similar issue was solved here: KnapsackPro/knapsack_pro-ruby#71 (this is old PR, we should use 0s as default time for not executed tests).

Concurrently npm package appears to not be compatible

It seems like we can't run Cypress tests simultaneously using the NPM package Concurrently v5.0.0 since as soon as the first test starts in both workers, the package exits with no error and the message is: [2]+ Stopped

We're trying to use the following command (and rest of the environment variables are in our .env file):

yarn concurrently "KNAPSACK_PRO_CI_NODE_TOTAL=2 KNAPSACK_PRO_CI_NODE_INDEX=0 knapsack-pro-cypress" "KNAPSACK_PRO_CI_NODE_TOTAL=2 KNAPSACK_PRO_CI_NODE_INDEX=1 knapsack-pro-cypress"

It works fine when using two shells for the tests and also with our Jenkins pipeline*.

Batches not optimized after using KNAPSACK_PRO_TEST_FILE_LIST_SOURCE_FILE

We've noticed a slowdown in our Jest tests after upgrading to @knapsack-pro/jest v5.4.1 and using the KNAPSACK_PRO_TEST_FILE_LIST_SOURCE_FILE option. What we're seeing is that the execution behavior of batches is very different and not optimized, leading to our Jest steps taking about 9 minutes (up from about 6 minutes). I've tried downgrading just the @knapsack-pro/core library from v4.0.0 to both v3.3.1 and v3.3.0, but did not see any change in behavior. However, reverting back from using KNAPSACK_PRO_TEST_FILE_LIST_SOURCE_FILE to KNAPSACK_PRO_TEST_FILE_PATTERN is what resolves the problem.

Here's a comparison of the two:

KNAPSACK_PRO_TEST_FILE_PATTERN
With this approach, you can see that the batches start with the slowest ones and get faster, leading to better durations when parallelized.

image

KNAPSACK_PRO_TEST_FILE_LIST_SOURCE_FILE
With this approach, you can see that the batches are not organized and as a result lead to many more batches being executed and durations taking much longer.

image

I tried to look through the changes, but didn't find an explanation for why the batching behavior would be different between the two approaches so I'm creating this issue in the hopes that the context you have can provide an answer.

Cypress component testing is very slow

Hello,

I started using Knapsack cypress pro for parallel executing component testing. I observed that the total duration is almost double due to continuous webpack compilation and project build before running the spec files.

Basically, when I specified 2 nodes for cypress component testing, each node invoked knapsack pro queue API to get the test spec for running and the API always returns only 1 spec file for executing the test spec instead it should return a list of test spec files which then get's build and executed without redundant webpack build step.

[Question] Using github actions and docker for knapsack-pro

I used to get knapsack-pro to work with my github actions. But recently I am changing to run github actions based on my custom docker image and I tried to configure the same things as before. But I get complaints about

app/node_modules/@knapsack-pro/core/lib/config/knapsack-pro-env.config.js:32
            throw new Error("Please set test suite API token in CI environment variables.\n      Please check README for the Knapsack Pro client library.");

my workflow.yml looks like this:

steps:
            - uses: actions/checkout@v2
            - name: Pull image
              run: docker pull <image> && docker-compose -f docker-compose.test.yml up -d
              # run: docker-compose up -d
            - name: Configure Knapsack Pro
              run: |
                  echo ::set-env name=KNAPSACK_PRO_TEST_SUITE_TOKEN_CYPRESS::${{ secrets.KNAPSACK_PRO_TEST_SUITE_TOKEN_CYPRESS }}
                  echo ::set-env name=KNAPSACK_PRO_TEST_FILE_PATTERN::"cypress/integration/**/*.spec.{js,ts}"
                  echo ::set-env name=KNAPSACK_PRO_CI_NODE_TOTAL::${{ matrix.ci_node_total }}
                  echo ::set-env name=KNAPSACK_PRO_CI_NODE_INDEX::${{ matrix.ci_node_index }}
            - name: run test
              run: docker exec server  npm run test:e2e:ci (this is just my script)

I enjoyed using knapsack a lot and spent quite a lot of time on setting this, I really appreciate your help.

Add test files/branch name encryption

about the feature

Allow user to enable encryption of sensitive data like:

  • test file paths
  • branch names

why we need this feature?

Some of the customers requested encryption for Jest.

idea how to implement it

Let's keep it simple.

Here is some info about the existing encryption feature for Ruby which might be too complex. We could do it simpler for Knapsack Pro in JavaScript (feature should be implemented in @knapsack-pro/core npm package so other packages like @knapsack-pro/jest or @knapsack-pro/cypress could use it).

In knapsack_pro ruby gem there is an encryption feature but it is a bit overcomplicated. It allows encrypting separately test file paths and branch names. It does not allow decryption so that's a downside for the development and performance of some of the features like RSpec split by examples because there is no simple way to decrypt test files on CI without encrypting all test files first to get SHA2 key (SHA2 value is used to compare SHA2 values from API response to identify test file paths).

In case of @knapsack-pro/core library I would recommend:

  • use some JS library (TODO: research what library would be a good fit) that allows to encrypt and decrypt string based on a key. If env var likeKNAPSACK_PRO_ENCRYPTION_KEY has value then it could mean encryption is enabled and the key will be used to encrypt and decrypt string like test file path & branch names.
  • There are some branch names that are exceptions and they should not be encrypted because Knapsack Pro API uses them to better split tests in some edge cases situation. Here is list of branch names that should never be encrypted.

story

https://trello.com/c/f494kFmB

Knapsack Jest runs not respecting cache

We've been using Knapsack Pro with our Jest tests for several months now with no problems; however, when we bump our version of Jest to the latest (29.7.0), the runs in Github Actions go from ~10 minutes each to ~50. The initial load of the app has always been very slow; however, it's a one-time cost, as I believe Jest uses a local cache for subsequent runs. Instead of something like this:

// ...Knapsack API response...
PASS a.test.ts (3 s)
PASS b.test.ts (2 s)
PASS c.test.ts (3 s)
// ...Knapsack API response...
PASS d.test.ts (3 s)
PASS e.test.ts (2 s)
PASS f.test.ts (3 s)

...we're seeing this:

// ...Knapsack API response...
PASS a.test.ts (75 s)
PASS b.test.ts (2 s)
PASS c.test.ts (3 s)
// ...Knapsack API response...
PASS d.test.ts (74 s)
PASS e.test.ts (2 s)
PASS f.test.ts (3 s)

...with the first test of each Jest run taking longer than a minute.

Is our suspicion correct, that Jest is for some reason ignoring the cache and reloading all the modules each time now?

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.