{"id":17125019,"url":"https://github.com/mattphillips/babel-plugin-gwt","last_synced_at":"2025-04-13T06:13:52.737Z","repository":{"id":40790643,"uuid":"119858632","full_name":"mattphillips/babel-plugin-gwt","owner":"mattphillips","description":"Data Driven Testing babel plugin inspired by Groovy's Spock framework 🖖","archived":false,"fork":false,"pushed_at":"2022-12-07T09:17:50.000Z","size":640,"stargazers_count":14,"open_issues_count":20,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-13T06:13:48.488Z","etag":null,"topics":["babel-plugin","bdd","data-driven","given","spock","tdd","testing","then","when","where"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/babel-plugin-gwt","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mattphillips.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-01T16:00:30.000Z","updated_at":"2020-12-08T22:29:16.000Z","dependencies_parsed_at":"2023-01-24T14:01:26.058Z","dependency_job_id":null,"html_url":"https://github.com/mattphillips/babel-plugin-gwt","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattphillips%2Fbabel-plugin-gwt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattphillips%2Fbabel-plugin-gwt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattphillips%2Fbabel-plugin-gwt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattphillips%2Fbabel-plugin-gwt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mattphillips","download_url":"https://codeload.github.com/mattphillips/babel-plugin-gwt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248670435,"owners_count":21142904,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["babel-plugin","bdd","data-driven","given","spock","tdd","testing","then","when","where"],"created_at":"2024-10-14T18:43:54.586Z","updated_at":"2025-04-13T06:13:52.711Z","avatar_url":"https://github.com/mattphillips.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\u003ch1\u003ebabel-plugin-gwt\u003c/h1\u003e\n\nData Driven Testing babel plugin inspired by Groovy's \u003ca href=\"http://spockframework.org/\"\u003eSpock\u003c/a\u003e framework\n\n🖖\n\u003c/div\u003e\n\n\u003chr /\u003e\n\n[![Build Status](https://img.shields.io/travis/mattphillips/babel-plugin-gwt.svg?style=flat-square)](https://travis-ci.org/mattphillips/babel-plugin-gwt)\n[![Code Coverage](https://img.shields.io/codecov/c/github/mattphillips/babel-plugin-gwt.svg?style=flat-square)](https://codecov.io/github/mattphillips/babel-plugin-gwt)\n[![version](https://img.shields.io/npm/v/babel-plugin-gwt.svg?style=flat-square)](https://www.npmjs.com/package/babel-plugin-gwt)\n[![downloads](https://img.shields.io/npm/dm/babel-plugin-gwt.svg?style=flat-square)](http://npm-stat.com/charts.html?package=babel-plugin-gwt\u0026from=2017-09-14)\n[![MIT License](https://img.shields.io/npm/l/babel-plugin-gwt.svg?style=flat-square)](https://github.com/mattphillips/babel-plugin-gwt/blob/master/LICENSE)\n[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)\n[![Roadmap](https://img.shields.io/badge/%F0%9F%93%94-roadmap-CD9523.svg?style=flat-square)](https://github.com/mattphillips/babel-plugin-gwt/blob/master/docs/ROADMAP.md)\n[![Examples](https://img.shields.io/badge/%F0%9F%92%A1-examples-ff615b.svg?style=flat-square)](https://github.com/mattphillips/babel-plugin-gwt/blob/master/docs/EXAMPLES.md)\n\n - ❤️ Data Tables\n - 🛀 Clean tests\n - 🎉 Multiple tests written once\n - 💪 Optional given, when, then API\n\n## Problem\n\nWriting clean descriptive tests can sometimes be difficult and cumbersome.\n\n## Solution\n\nThis plugin provides syntactic sugar to make writing well documented data driven tests easy and enjoyable.\n\n[Data Driven Testing](https://en.wikipedia.org/wiki/Data-driven_testing) is when we test the same behavior\nmultiple times with different parameters and assertions, `babel-plugin-gwt's` data driven testing support makes this a\nfirst class feature.\n\n`babel-plugin-gwt` gives your standard Javascript tests four new blocks `given`, `when`, `then`, `where` (you can\ncontinue to use whichever test runner and assertion library that you like with this plugin).\n\n - `given`, `when`, `then` blocks are used to generate your test title making it easier to write, read and maintain\n your test.\n\n - Data Tables are supported with the `where` block used to write test data for your test to be ran multiple times with\n  different inputs.\n\n## Installation\n\nWith npm:\n```sh\nnpm install --save-dev babel-plugin-gwt\n```\n\nWith yarn:\n```sh\nyarn add -D babel-plugin-gwt\n```\n\n## Setup\n\n### .babelrc\n\n```json\n{\n  \"plugins\": [\"babel-plugin-gwt\"]\n}\n```\n\n### CLI\n\n```sh\nbabel --plugins babel-plugin-gwt script.js\n```\n\n### Node\n\n```javascript\nrequire('babel-core').transform('code', {\n  plugins: ['babel-plugin-gwt'],\n})\n```\n\n## Usage\n\n### Basic\n\nA simple test with `babel-plugin-gwt` could look something like:\n\n```js\nit('add', () =\u003e {\n  given: 'a and b'\n  const a = 1;\n  const b = 1;\n\n  when: 'added'\n  const actual = a + b;\n\n  then: 'returns 2'\n  expect(actual).toBe(2);\n});\n```\n`↓ ↓ ↓ ↓ ↓ ↓`\n\n![simple test](assets/simple.png)\n\n### With Data Table\n\nThis test can become more powerful by using the `where` block to run the same test multiple times with different data.\nThe where block allows you to define variables that are available anywhere in the test and to use the `$` symbol in your\ntest title and `given`, `when`, `then` blocks to interpolate values into the generated test title.\n\n```js\nit('add', () =\u003e {\n  when: '$a is added to $b'\n  const actual = a + b;\n\n  then: '$expected is returned'\n  expect(actual).toBe(expected);\n\n  where: {\n    a | b || expected\n    0 | 0 || 0\n    1 | 0 || 1\n    0 | 1 || 1\n    1 | 1 || 2\n  }\n});\n```\n`↓ ↓ ↓ ↓ ↓ ↓`\n\n![where tests](assets/where.png)\n\n### API\n\nAll label blocks are optional, and some like `given` may not make sense for every test.\n\n#### `given`\n\nThe `given` block is used to describe the inputs of your test.\n\n - Arguments: `String`\n\nExample: `given: 'some input'`\n\n#### `when`\n\nThe `when` block is used to describe the behaviour being tested.\n\n - Arguments: `String`\n\nExample: `when: 'something happens'`\n\n#### `then`\n\nThe `then` block is used to describe the assertions being made.\n\n - Arguments: `String`\n\nExample: `then: 'it should be ...'`\n\n#### `where`\n\nThe `where` block is used to supply your test with a data table. The table must have the following structure:\n - The first row must be variable names you wish to use within the test. These will be hoisted into the whole\n  scope of the test block and so can be used anywhere inside of the test.\n - All other rows can be data and variables available in the outer scope that you may be testing\n - Columns of data are separated with `|`, a convention is to use two pipes (`||`) for any expected values (although\n this is just a convention under the hood both `|` and `||` are treated the same).\n\nExample:\n```js\n  where: {\n    a | b || expected\n    0 | 0 || 0\n    1 | 0 || 1\n    0 | 1 || 1\n    1 | 1 || 2\n  }\n```\n\n#### interpolation\n\nAll description blocks (`given`, `when`, and `then`) and the usual test description can add values to be interpolated\nwith the `$` symbol infront of the variable name defined in the `where` block table.\n\n## Supported testing frameworks\n\n`babel-plugin-gwt` supports all of the following test blocks: `it`, `fit`, `xit`, `it.only`, `it.skip`, `test`,\n`ftest`, `xtest`, `test.only`, `test.skip`.\n\nThat means that the following frameworks are supported:\n\n - [Jest](https://facebook.github.io/jest/)\n - [Ava](https://github.com/avajs/ava#usage)\n - [Moca](https://mochajs.org/)\n - [Tape](https://github.com/substack/tape)\n - [Cypress](https://www.cypress.io/)\n - Other? Send PR to add 🙌\n\n## ⚠️ Linting\n\nSome of the syntaxes used within this plugin will more than likely upset most linters so it is probably advisable to\ndisable them within the tests using `babel-plugin-gwt`.\n\nFor example eslint:\n\n```js\nit('add', () =\u003e {\n  /* eslint-disable no-undef, no-unused-labels */\n  when: '$a is added to $b'\n  const actual = a + b;\n\n  then: '$expected is returned'\n  expect(actual).toBe(expected);\n\n  where: {\n    a | b || expected\n    0 | 0 || 0\n    1 | 0 || 1\n    0 | 1 || 1\n    1 | 1 || 2\n  }\n});\n```\n\n## ❌ Object/Array literal broken syntax\n\nWithin the where block the first column does not support `Object`(`{}`) or `Array` (`[]`) literals\n\nNot supported:\n```js\nwhere: {\n  obj  | key   | value || expected\n  {}   | 'foo' | 'bar' || { foo: 'bar' }\n}\n```\n\nSupported:\n```js\nwhere: {\n  key  | obj | value || expected\n  'foo'| {}  | 'bar' || { foo: 'bar' }\n}\n```\n\n## Other solutions\n\n - [jest-each](https://www.github.com/mattphillips/jest-each)\n - [mocha-each](https://www.npmjs.com/package/mocha-each)\n\n## Contributors\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --\u003e\n\u003c!-- prettier-ignore --\u003e\n| [\u003cimg src=\"https://avatars0.githubusercontent.com/u/5610087?v=4\" width=\"100px;\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eMatt Phillips\u003c/b\u003e\u003c/sub\u003e](http://mattphillips.io)\u003cbr /\u003e[💻](https://github.com/mattphillips/babel-plugin-gwt/commits?author=mattphillips \"Code\") [📖](https://github.com/mattphillips/babel-plugin-gwt/commits?author=mattphillips \"Documentation\") [💡](#example-mattphillips \"Examples\") [🤔](#ideas-mattphillips \"Ideas, Planning, \u0026 Feedback\") [⚠️](https://github.com/mattphillips/babel-plugin-gwt/commits?author=mattphillips \"Tests\") |\n| :---: |\n\u003c!-- ALL-CONTRIBUTORS-LIST:END --\u003e\n\n## LICENSE\n\n[MIT](/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattphillips%2Fbabel-plugin-gwt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmattphillips%2Fbabel-plugin-gwt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattphillips%2Fbabel-plugin-gwt/lists"}