Test-It is a test framework that gives you the best of node AND the browser.
Test-It is a test framework that combines the best of node and the browser.
describe
, it
, expect
API as Jest
debug
instead of it
to open your test in a browser and debug with Chrome DevToolsexpect(value).toMatchSnapshot()
await TestIt.captureScreenshot()
to capture a screenshot of the page (returns a Buffer
of PNG data)expect(pngBuffer).toMatchImageSnapshot()
When running in a test framework built on top of node, like Jest, you don't have access to real DOM APIs, like window
and document
.
Some test frameworks (Jest included) try to get around this by using jsdom, but it has limitations; since there's no layout or rendering engine, you can't test things that rely on:
.getBoundingClientRect()
document.body.innerText
This is usually solved by running the tests in a real browser, using something like Karma. But, that introduces other limitations:
require
in your tests, so your tests need to get compiled somehowfs
in your tests, so you can't write snapshots or screenshots to disk.If you want to do something that requires a real DOM as well as require
or fs
, then you have to write a complex server that ties everything together.
For example, if you want to render individual parts of your application to the DOM, and then perform Visual Regression Testing by taking screenshots of those components, you need to:
require
)fs
to write screenshots to diskIt's very complicated, and it's a lot to set up.
If there was a test framework that could run code with access to a Real DOM and node APIs, then we wouldn't need any of those things:
fs
, because you can access fs
directlyrequire
right in your testsTest-It is that test framework.
When you run your tests in Test-It, you have access to real DOM APIs and all of node's APIs, including require
.
Unlike test frameworks built on top of jsdom, the DOM APIs here are real; your tests are running in a real Chromium browser.
But also, unlike test frameworks built on top Karma, the Node APIs here are also real; your tests are running with full access to all node APIs (such as require
, fs
, etc).
Test-It gives you the best of both worlds.
First, install @test-it/core
and @test-it/cli
:
npm install --save-dev @test-it/core @test-it/cli
Then, add the following to your package.json
:
"scripts": {
"test-it": "test-it"
}
Then, run Test-It using npm:
npm run test-it
If you use TypeScript, you can add "./node_modules/@test-it/core/globals.d.ts"
to your tsconfig.json
's files
array to get types for the following globals (which are provided by Test-It):
expect
describe
fdescribe
xdescribe
test
it
debug
fit
xit
beforeEach
beforeAll
before
afterEach
afterAll
after
TestIt
By default, Test-It will run against any test files named like *.test.js
.
To change this, you can pass glob strings to the test-it
CLI:
npm run test-it -- './**/*.spec.js' '!**/node_modules/**'
You can also pass specific filenames:
npm run test-it -- './tests/first.spec.js' './tests/second.spec.js'
For more usage information run npm run test-it -- --help
.