GithubHelp home page GithubHelp logo

test-all-versions's Introduction

test-all-versions

Run your test suite against all published versions of a given dependency.

npm codecov js-standard-style

Usage

Use the tav command to run the tests:

$ tav [options] [<module> <semver> <command> [args...]]

Example running node test.js against all versions of the mysql module that satisfies the ^2.0.0 semver:

tav mysql ^2.0.0 node test.js

options

  • --help - Output usage info
  • --quiet - Don't output stdout from tests unless an error occors
  • --verbose - Output a lot of information while running
  • --compat - Output just module version compatibility - no errors
  • --ci - When running tav together with a .tav.yml file, use this argument to only run the tests on a CI server. This allows you to add tav to your npm test command without spending time running tav tests in development.

.tav.yml

If tav is run without specifying a module, it will instead look for a .tav.yml file in cwd and expect that to contain all its configuration. This is similar to how Travis CI works with .travis.yml.

The following is an example .tav.yml file that runs a subset of tests against all versions of the mysql module that satisfies ^2.0.0 and all versions of the pg module that satisfies *:

mysql:
  versions: ^2.0.0
  commands: tape test/mysql/*.js
pg:
  versions: "*"
  commands:
    - node test/pg1.js
    - node test/pg2.js

Node.js version

You can optionally specify a node key in case you want to limit which verisons of Node.js the tests for a specific package runs under. The value must be a valid semver range:

mysql:
  node: ">=1.0.0"
  versions: ^2.0.0
  commands: node test/mysql.js

Peer Dependencies

If a package or a test needs certain peer dependencies installed in order to be able to run, use the peerDependencies key. The value can be either a single value like shown below, or a list of values just like with the commands key:

graphql-express:
  peerDependencies: [email protected]
  versions: ^0.6.1
  commands: node test/graphql-express.js

Setup and Teardown

If you need to run a script before or after a command, use the preinstall, pretest and posttest keys:

graphql:
  versions: ^0.7.0
  preinstall: rm -fr node_modules/graphql-express
  commands: node test/graphql.js

Usage:

  • preinstall: runs before npm install
  • pretest: runs before each command in the commands list
  • posttest: runs after each comamnd in the commands list

Multiple test-groups per module

If you need multiple test-groups for the same module, use - to specify an array of test-groups:

mysql:
  - versions: ^1.0.0
    commands: node test/mysql-1x.js
  - versions: ^2.0.0
    commands: node test/mysql-2x.js

Test matrix

If you specify environment variables using the env key, the test commands will be run once per element in the env array. In the following example node test/mysql.js will run twice for each version matching ^2.0.0 - once with MYSQL_HOST=server1.example.net MYSQL_PWD=secret! and once with MYSQL_HOST=server2.example.net.

mysql:
  env:
    - MYSQL_HOST=server1.example.net MYSQL_PWD=secret!
    - MYSQL_HOST=server2.example.net
  versions: ^2.0.0
  commands: node test/mysql.js

If more than one test-case is needed for a given module, the environment variables can shared between them using the following syntax:

mysql:
  env:
    - MYSQL_HOST=server1.example.net MYSQL_PWD=secret!
    - MYSQL_HOST=server2.example.net
  jobs:
    - versions: ^1.0.0
      commands: node test/mysql-1x.js
    - versions: ^2.0.0
      commands: node test/mysql-2x.js

Advanced versions usage

The versions field takes two types of arguments:

  • A string representing a semver-range (e.g. ^2.0.0)
  • An object with the following properties:
    • include (required): The semver-range to include in testing. Same effect as the versions string.
    • exclude (optional): The semver-range of versions to exclude. Versions matching this range would be removed from the include list if present.
    • mode (optional): The way you want to pick versions from the ones resolved based on include/exclude. Possible values are:
      • all (default): All versions matching the desired range.
      • latest-majors: Only pick the latest version of each major matching the desired range.
      • latest-minors: Only pick the latest version of each minor matching the desired range.
      • max-{N}(-<algo>): Only pick N number of versions within the desired range, where {N} is a number larger than 2. The optional -<algo> postfix can be used to specify the algorithm used for picking the versions inbetween. Possible algorithmes are:
        • evenly (default): Evenly space out which versions to pick, always including the first and last version in the desired range.
        • random: Pick N versions at random within the desired range.
        • latest: Pick the latest N versions within the desired range.
        • popular: Pick the N most popular versions based on last weeks download count from npm.
Exampels

Test all versions within ^1.0.0, except 1.2.3:

mysql:
  versions:
    include: ^1.0.0
    exclude: 1.2.3
  commands: node test/mysql.js

Test 5 versions in the ^1.0.0 range (evenly spaced within the range):

mysql:
  versions:
    include: ^1.0.0
    mode: max-5
  commands: node test/mysql.js

Test the 5 most popular versions in the ^1.0.0 range (based on download count within the last week):

mysql:
  versions:
    include: ^1.0.0
    mode: max-5-popular
  commands: node test/mysql.js

Whitelist tests with environment variables

You can use the enironment variable TAV to limit which module from the .tav.yml file to test:

TAV=mysql

This allows you to create a build-matrix on servers like Travis CI where each module in your .tav.yml file is tests in an individual build. You can also comma separate multiple names if needed:

TAV=mysql,pg

To see an example of this in action, check out the .travis.yml and .tav.yml files under the Elastic APM Node.js Agent module.

License

MIT

test-all-versions's People

Contributors

trentm avatar watson avatar zaubernerd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

test-all-versions's Issues

Restore originally installed version after tav run

After running tav, the targeted dependency is still installed in the last version checked by tav:

  1. npm install some-dependency@2
  2. tav some-dependency "^1.0.0" npm test
  3. some-dependency is now installed in version 1 in node_modules

This is very confusing, especially if tav exits early after a failed test. I suggest that tav automatically restores the originally installed version before it exits.

Matrix test multiple versions of multiple packages

As far as I understand, it's currently only possible to test multiple versions a single package using a given command. Say run npm test1 for 3 different versions of dependency1. It's also possible to add more than one such configuration, e.g. also run npm test2 for 2 different versions of dependency2.

What's currently not possible (please correct me if I'm wrong) is to "matrix test" these 3 * 2 dependencies (using a single command): run npm test_matrix for

  • dependency1 (version 1) and dependency2 (version 1)
  • dependency1 (version 1) and dependency2 (version 2)
  • dependency1 (version 2) and dependency2 (version 1)
  • dependency1 (version 2) and dependency2 (version 2)
  • dependency1 (version 3) and dependency2 (version 1)
  • dependency1 (version 3) and dependency2 (version 2)

Basically, run my test suite for all possible combinations of supported dependency versions across multiple dependencies.

Provide a way to test groups of packages in version jumps

Use case: I want to test against react-dom 0.14 or 15.x which requires a peer dependency of react. However the version that is needed is always in sync. This will be true for any large package group managed with https://lernajs.io/

Something like this currently doesn't work

react-dom:
  peerDependencies: react
  versions: 0.14.x || 15.3.x
  commands: npm run test

Wondering if you could extend the config to allow a structure that can specify any number of packages. And then run the tests upgrading those packages in sync.

Example:

react-test-1:
  packages:
    - react
    - react-dom
  versions: 0.14.x || 15.3.x
  commands: npm run test

Thoughts?

Doesn't appear to work in Windows.

C:\code\eslint-plugin-json-files>tav    
-- required packages ["[email protected]"]
-- installing ["[email protected]"]       
-- error installing ["[email protected]"] ('C:\Program' is not recognized as an internal or external command,
operable program or batch file.
) - retrying (2/10)...
-- installing ["[email protected]"]
-- error installing ["[email protected]"] ('C:\Program' is not recognized as an internal or external command,
operable program or batch file.
) - retrying (3/10)...
-- installing ["[email protected]"]
-- error installing ["[email protected]"] ('C:\Program' is not recognized as an internal or external command,
operable program or batch file.
) - retrying (4/10)...
-- installing ["[email protected]"]
-- error installing ["[email protected]"] ('C:\Program' is not recognized as an internal or external command,
operable program or batch file.
) - retrying (5/10)...
-- installing ["[email protected]"]
-- error installing ["[email protected]"] ('C:\Program' is not recognized as an internal or external command,
operable program or batch file.
) - retrying (6/10)...
-- installing ["[email protected]"]
-- error installing ["[email protected]"] ('C:\Program' is not recognized as an internal or external command,
operable program or batch file.
) - retrying (7/10)...
-- installing ["[email protected]"]
-- error installing ["[email protected]"] ('C:\Program' is not recognized as an internal or external command,
operable program or batch file.
) - retrying (8/10)...
-- installing ["[email protected]"]
-- error installing ["[email protected]"] ('C:\Program' is not recognized as an internal or external command,
operable program or batch file.
) - retrying (9/10)...
-- installing ["[email protected]"]
-- error installing ["[email protected]"] ('C:\Program' is not recognized as an internal or external command,
operable program or batch file.
) - retrying (10/10)...
-- installing ["[email protected]"]
-- error installing ["[email protected]"] - aborting!
Error: 'C:\Program' is not recognized as an internal or external command,
operable program or batch file.

    at ChildProcess.<anonymous> (C:\code\eslint-plugin-json-files\node_modules\spawn-npm-install\index.js:60:10)
    at Object.onceWrapper (events.js:291:20)
    at ChildProcess.emit (events.js:203:13)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
-- fatal: undefined

Enhance `versions` configuration to accept options object

There are a couple of scenarios where a more concise configuration of versions property.

  • Some of the packages you're testing have a bad version within the range you want to test. There should be a way to exclude them.
  • Some packages release patches very frequently @aws-sdk clients for example and we would want to test on a subset to speed up testing. Ref: elastic/apm-agent-nodejs#2020

The proposal is to allow to pass an object into versions property to be more specific in which version we would want to test. That object would have the following props:

  • include (required): the range to include in testing. Same effect that the versions string
  • exclude (optional): the range of versions to exclude. Versions matching this range would be removed from the include list if present.
  • mode (optional): the way you want to pick versions from the ones resolved based on include/exclude. Possible values would be
    • latest-majors: only pick the latest major versions
    • latest-minors: only pick the latest minor versions
    • max-{N}: where {N} is a number. Pick 1st, last and {N} in between

At https://github.com/elastic/apm-agent-nodejs there is an implementation using a sibling property and a script which does the version resolution and updates the versions property. I think it could be easy to port it here.

Samples of the prop being used:

Possible to run without `npm`?

I'm using Yarn, and don't have npm on my system at the moment.

Running tav (including through yarn run) gives me:

Error: Command failed: npm -v

which appears to be caused by this line.

Would it be possible to skip this check and/or add in support for additional package managers?

Option to continue running tests after a failure

Currently, tav exits after the first test failure. I'd love to be able to have an option which allows me to continue through all versions under test even if some of them fail -- knowing which versions exactly are affected by a failing test case is very useful to know.

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.