Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
babel-plugin-gwt
Advanced tools
Data Driven Testing babel plugin inspired by Groovy's Spock framework
Writing clean descriptive tests can sometimes be difficult and cumbersome.
This plugin provides syntactic sugar to make writing well documented data driven tests easy and enjoyable.
Data Driven Testing is when we test the same behavior
multiple times with different parameters and assertions, babel-plugin-gwt's
data driven testing support makes this a
first class feature.
babel-plugin-gwt
gives your standard Javascript tests four new blocks given
, when
, then
, where
(you can
continue to use whichever test runner and assertion library that you like with this plugin).
given
, when
, then
blocks are used to generate your test title making it easier to write, read and maintain
your test.
Data Tables are supported with the where
block used to write test data for your test to be ran multiple times with
different inputs.
With npm:
npm install --save-dev babel-plugin-gwt
With yarn:
yarn add -D babel-plugin-gwt
{
"plugins": ["babel-plugin-gwt"]
}
babel --plugins babel-plugin-gwt script.js
require('babel-core').transform('code', {
plugins: ['babel-plugin-gwt'],
})
A simple test with babel-plugin-gwt
could look something like:
it('add', () => {
given: 'a and b'
const a = 1;
const b = 1;
when: 'added'
const actual = a + b;
then: 'returns 2'
expect(actual).toBe(2);
});
↓ ↓ ↓ ↓ ↓ ↓
This test can become more powerful by using the where
block to run the same test multiple times with different data.
The where block allows you to define variables that are available anywhere in the test and to use the $
symbol in your
test title and given
, when
, then
blocks to interpolate values into the generated test title.
it('add', () => {
when: '$a is added to $b'
const actual = a + b;
then: '$expected is returned'
expect(actual).toBe(expected);
where: {
a | b || expected
0 | 0 || 0
1 | 0 || 1
0 | 1 || 1
1 | 1 || 2
}
});
↓ ↓ ↓ ↓ ↓ ↓
All label blocks are optional, and some like given
may not make sense for every test.
given
The given
block is used to describe the inputs of your test.
String
Example: given: 'some input'
when
The when
block is used to describe the behaviour being tested.
String
Example: when: 'something happens'
then
The then
block is used to describe the assertions being made.
String
Example: then: 'it should be ...'
where
The where
block is used to supply your test with a data table. The table must have the following structure:
|
, a convention is to use two pipes (||
) for any expected values (although
this is just a convention under the hood both |
and ||
are treated the same).Example:
where: {
a | b || expected
0 | 0 || 0
1 | 0 || 1
0 | 1 || 1
1 | 1 || 2
}
All description blocks (given
, when
, and then
) and the usual test description can add values to be interpolated
with the $
symbol infront of the variable name defined in the where
block table.
babel-plugin-gwt
supports all of the following test blocks: it
, fit
, xit
, it.only
, it.skip
, test
,
ftest
, xtest
, test.only
, test.skip
.
That means that the following frameworks are supported:
Some of the syntaxes used within this plugin will more than likely upset most linters so it is probably advisable to
disable them within the tests using babel-plugin-gwt
.
For example eslint:
it('add', () => {
/* eslint-disable no-undef, no-unused-labels */
when: '$a is added to $b'
const actual = a + b;
then: '$expected is returned'
expect(actual).toBe(expected);
where: {
a | b || expected
0 | 0 || 0
1 | 0 || 1
0 | 1 || 1
1 | 1 || 2
}
});
Within the where block the first column does not support Object
({}
) or Array
([]
) literals
Not supported:
where: {
obj | key | value || expected
{} | 'foo' | 'bar' || { foo: 'bar' }
}
Supported:
where: {
key | obj | value || expected
'foo'| {} | 'bar' || { foo: 'bar' }
}
Matt Phillips 💻 📖 💡 🤔 ⚠️ |
---|
FAQs
Data Driven Testing babel plugin inspired by Groovy's Spock framework
We found that babel-plugin-gwt demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.