@bagaar/ember-graphql-mocking 0.3.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +35 -0
- package/README.md +19 -8
- package/addon-test-support/index.js +17 -21
- package/package.json +23 -22
- package/public/mockServiceWorker.js +1 -1
- package/.husky/commit-msg +0 -4
- package/RELEASE.md +0 -60
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,39 @@
|
|
|
1
1
|
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
## v0.5.0 (2022-06-24)
|
|
6
|
+
|
|
7
|
+
#### :boom: Breaking Change
|
|
8
|
+
* [#29](https://github.com/Bagaar/ember-graphql-mocking/pull/29) Update `msw` to v0.42.3 ([@bertdeblock](https://github.com/bertdeblock))
|
|
9
|
+
* [#27](https://github.com/Bagaar/ember-graphql-mocking/pull/27) Drop support for Ember v3.24 ([@bertdeblock](https://github.com/bertdeblock))
|
|
10
|
+
* [#26](https://github.com/Bagaar/ember-graphql-mocking/pull/26) Drop support for Node v12 ([@bertdeblock](https://github.com/bertdeblock))
|
|
11
|
+
|
|
12
|
+
#### Committers: 1
|
|
13
|
+
- Bert De Block ([@bertdeblock](https://github.com/bertdeblock))
|
|
14
|
+
|
|
15
|
+
## v0.4.1 (2022-02-09)
|
|
16
|
+
|
|
17
|
+
#### :bug: Bug Fix
|
|
18
|
+
* [#24](https://github.com/Bagaar/ember-graphql-mocking/pull/24) Don't automatically stop the worker when all tests are done (fix compat with `ember-cli-code-coverage@v1`) ([@bertdeblock](https://github.com/bertdeblock))
|
|
19
|
+
|
|
20
|
+
#### :memo: Documentation
|
|
21
|
+
* [#19](https://github.com/Bagaar/ember-graphql-mocking/pull/19) Fix install command in docs ([@bertdeblock](https://github.com/bertdeblock))
|
|
22
|
+
|
|
23
|
+
#### :house: Internal
|
|
24
|
+
* [#22](https://github.com/Bagaar/ember-graphql-mocking/pull/22) Don't publish `.husky` folder and `RELEASE.md` file ([@bertdeblock](https://github.com/bertdeblock))
|
|
25
|
+
|
|
26
|
+
#### Committers: 1
|
|
27
|
+
- Bert De Block ([@bertdeblock](https://github.com/bertdeblock))
|
|
28
|
+
|
|
29
|
+
## v0.4.0 (2022-02-03)
|
|
30
|
+
|
|
31
|
+
#### :rocket: Enhancement
|
|
32
|
+
* [#18](https://github.com/Bagaar/ember-graphql-mocking/pull/18) Make `msw` start options configurable ([@bertdeblock](https://github.com/bertdeblock))
|
|
33
|
+
|
|
34
|
+
#### Committers: 1
|
|
35
|
+
- Bert De Block ([@bertdeblock](https://github.com/bertdeblock))
|
|
36
|
+
|
|
2
37
|
## v0.3.2 (2022-02-02)
|
|
3
38
|
|
|
4
39
|
#### :house: Internal
|
package/README.md
CHANGED
|
@@ -6,18 +6,16 @@
|
|
|
6
6
|
|
|
7
7
|
Ember addon for mocking GraphQL requests using [Mock Service Worker (MSW)](https://github.com/mswjs/msw).
|
|
8
8
|
|
|
9
|
-
> :warning: Experimental mocking package used at Bagaar. You probably shouldn't use this for now.
|
|
10
|
-
|
|
11
9
|
## Compatibility
|
|
12
10
|
|
|
13
|
-
- Ember.js v3.
|
|
14
|
-
- Ember CLI v3.
|
|
15
|
-
- Node.js
|
|
11
|
+
- Ember.js v3.28 or above
|
|
12
|
+
- Ember CLI v3.28 or above
|
|
13
|
+
- Node.js v14 or above
|
|
16
14
|
|
|
17
15
|
## Installation
|
|
18
16
|
|
|
19
17
|
```shell
|
|
20
|
-
ember install bagaar/ember-graphql-mocking
|
|
18
|
+
ember install @bagaar/ember-graphql-mocking
|
|
21
19
|
```
|
|
22
20
|
|
|
23
21
|
## Usage
|
|
@@ -50,6 +48,17 @@ setupEmberGraphqlMocking(schema); // 3.
|
|
|
50
48
|
start();
|
|
51
49
|
```
|
|
52
50
|
|
|
51
|
+
If you want to pass along additional [start options](https://mswjs.io/docs/api/setup-worker/start#options)
|
|
52
|
+
to MSW's service worker, you can do so by defining an `mswStartOptions` object:
|
|
53
|
+
|
|
54
|
+
```js
|
|
55
|
+
setupEmberGraphqlMocking(schema, {
|
|
56
|
+
mswStartOptions: {
|
|
57
|
+
// Additional MSW start options...
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
```
|
|
61
|
+
|
|
53
62
|
### 2. Write an Acceptance Test
|
|
54
63
|
|
|
55
64
|
1. Import `mockResolvers` and `setupGraphqlTest`
|
|
@@ -60,14 +69,14 @@ start();
|
|
|
60
69
|
|
|
61
70
|
`mockResolvers` accepts an object that consists of one or more resolvers. The key must be the name of the mocked operation, the value can either be a response object _or_ a function that returns a response object.
|
|
62
71
|
|
|
63
|
-
> **NOTE:** Make sure that your operations are named in order for `@bagaar/ember-graphql-mocking` to function properly.
|
|
72
|
+
> **NOTE:** Make sure that your operations are [named](https://graphql.org/learn/queries/#operation-name) in order for `@bagaar/ember-graphql-mocking` to function properly.
|
|
64
73
|
|
|
65
74
|
```javascript
|
|
66
75
|
// tests/acceptance/my-acceptance-test.js
|
|
67
76
|
|
|
68
77
|
import { module, test } from 'qunit';
|
|
69
78
|
import { visit, currentURL } from '@ember/test-helpers';
|
|
70
|
-
import { setupApplicationTest } from '
|
|
79
|
+
import { setupApplicationTest } from 'my-app/tests/helpers';
|
|
71
80
|
import { mockResolvers, setupGraphqlTest } from '@bagaar/ember-graphql-mocking/test-support'; // 1.
|
|
72
81
|
|
|
73
82
|
module('Acceptance | ember graphql mocking', function (hooks) {
|
|
@@ -94,6 +103,8 @@ module('Acceptance | ember graphql mocking', function (hooks) {
|
|
|
94
103
|
});
|
|
95
104
|
```
|
|
96
105
|
|
|
106
|
+
> **NOTE:** Calling `mockResolvers` multiple times within a single test, will simply merge all resolvers into a single root.
|
|
107
|
+
|
|
97
108
|
💡 Working versions of these code examples can be found in [this addon's `tests` folder](./tests/).
|
|
98
109
|
|
|
99
110
|
## Contributing
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
import { assert } from '@ember/debug';
|
|
2
2
|
import { buildASTSchema, graphql } from 'graphql';
|
|
3
|
+
import merge from 'lodash.merge';
|
|
3
4
|
import { graphql as mswGraphql, setupWorker } from 'msw';
|
|
4
|
-
import { done as qunitDone } from 'qunit';
|
|
5
5
|
|
|
6
6
|
const IS_TESTEM = Boolean(window.Testem);
|
|
7
7
|
const DEFAULT_OPTIONS = {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
mswStartOptions: {
|
|
9
|
+
quiet: IS_TESTEM,
|
|
10
|
+
serviceWorker: {
|
|
11
|
+
options: {
|
|
12
|
+
scope: IS_TESTEM ? window.location.pathname : '/tests',
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
},
|
|
10
16
|
};
|
|
11
17
|
|
|
12
18
|
let isSetupGraphqlTestCalled = false;
|
|
@@ -14,14 +20,10 @@ let root = null;
|
|
|
14
20
|
let worker = null;
|
|
15
21
|
|
|
16
22
|
export function setupEmberGraphqlMocking(schemaDocument, providedOptions) {
|
|
17
|
-
const options = {
|
|
18
|
-
...DEFAULT_OPTIONS,
|
|
19
|
-
...providedOptions,
|
|
20
|
-
};
|
|
23
|
+
const options = merge({}, DEFAULT_OPTIONS, providedOptions);
|
|
21
24
|
|
|
22
25
|
createWorker(options);
|
|
23
26
|
createGraphqlOperationHandler(schemaDocument);
|
|
24
|
-
qunitDone(destroyWorker);
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
export function setupGraphqlTest(hooks) {
|
|
@@ -43,22 +45,16 @@ export function getWorker() {
|
|
|
43
45
|
return worker;
|
|
44
46
|
}
|
|
45
47
|
|
|
46
|
-
function
|
|
47
|
-
worker
|
|
48
|
+
export function destroyWorker() {
|
|
49
|
+
worker.stop();
|
|
48
50
|
|
|
49
|
-
worker
|
|
50
|
-
quiet: options.quiet,
|
|
51
|
-
serviceWorker: {
|
|
52
|
-
options: {
|
|
53
|
-
scope: options.scope,
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
});
|
|
51
|
+
worker = null;
|
|
57
52
|
}
|
|
58
53
|
|
|
59
|
-
function
|
|
60
|
-
worker
|
|
61
|
-
|
|
54
|
+
function createWorker(options) {
|
|
55
|
+
worker = setupWorker();
|
|
56
|
+
|
|
57
|
+
worker.start(options.mswStartOptions);
|
|
62
58
|
}
|
|
63
59
|
|
|
64
60
|
function createGraphqlOperationHandler(schemaDocument) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bagaar/ember-graphql-mocking",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Ember addon for mocking GraphQL requests using Mock Service Worker (MSW).",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ember-addon"
|
|
@@ -34,25 +34,25 @@
|
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"broccoli-funnel": "^3.0.5",
|
|
36
36
|
"broccoli-merge-trees": "^4.2.0",
|
|
37
|
-
"ember-auto-import": "^2.
|
|
37
|
+
"ember-auto-import": "^2.4.1",
|
|
38
38
|
"ember-cli-babel": "^7.26.11",
|
|
39
39
|
"graphql": "^16.3.0",
|
|
40
|
-
"
|
|
41
|
-
"
|
|
40
|
+
"lodash.merge": "^4.6.2",
|
|
41
|
+
"msw": "^0.42.3"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@commitlint/cli": "^
|
|
45
|
-
"@commitlint/config-conventional": "^
|
|
44
|
+
"@commitlint/cli": "^17.0.2",
|
|
45
|
+
"@commitlint/config-conventional": "^17.0.2",
|
|
46
46
|
"@ember/optional-features": "^2.0.0",
|
|
47
|
-
"@ember/test-helpers": "^2.
|
|
48
|
-
"@embroider/test-setup": "^1.
|
|
49
|
-
"@glimmer/component": "^1.
|
|
50
|
-
"@glimmer/tracking": "^1.
|
|
47
|
+
"@ember/test-helpers": "^2.7.0",
|
|
48
|
+
"@embroider/test-setup": "^1.6.0",
|
|
49
|
+
"@glimmer/component": "^1.1.2",
|
|
50
|
+
"@glimmer/tracking": "^1.1.2",
|
|
51
51
|
"babel-eslint": "^10.1.0",
|
|
52
52
|
"broccoli-asset-rev": "^3.0.0",
|
|
53
|
-
"ember-apollo-client": "^
|
|
54
|
-
"ember-cli": "~4.
|
|
55
|
-
"ember-cli-dependency-checker": "^3.
|
|
53
|
+
"ember-apollo-client": "^4.0.2",
|
|
54
|
+
"ember-cli": "~4.4.0",
|
|
55
|
+
"ember-cli-dependency-checker": "^3.3.1",
|
|
56
56
|
"ember-cli-htmlbars": "^6.0.1",
|
|
57
57
|
"ember-cli-inject-live-reload": "^2.1.0",
|
|
58
58
|
"ember-cli-sri": "^2.1.1",
|
|
@@ -64,27 +64,28 @@
|
|
|
64
64
|
"ember-page-title": "^7.0.0",
|
|
65
65
|
"ember-qunit": "^5.1.5",
|
|
66
66
|
"ember-resolver": "^8.0.3",
|
|
67
|
-
"ember-source": "~4.
|
|
67
|
+
"ember-source": "~4.4.0",
|
|
68
68
|
"ember-source-channel-url": "^3.0.0",
|
|
69
|
-
"ember-template-lint": "^4.
|
|
69
|
+
"ember-template-lint": "^4.8.0",
|
|
70
70
|
"ember-try": "^2.0.0",
|
|
71
71
|
"eslint": "^7.32.0",
|
|
72
|
-
"eslint-config-prettier": "^8.
|
|
73
|
-
"eslint-plugin-ember": "^10.
|
|
72
|
+
"eslint-config-prettier": "^8.5.0",
|
|
73
|
+
"eslint-plugin-ember": "^10.6.1",
|
|
74
74
|
"eslint-plugin-node": "^11.1.0",
|
|
75
75
|
"eslint-plugin-prettier": "^4.0.0",
|
|
76
76
|
"eslint-plugin-qunit": "^7.2.0",
|
|
77
|
-
"husky": "^
|
|
77
|
+
"husky": "^8.0.1",
|
|
78
78
|
"loader.js": "^4.7.0",
|
|
79
79
|
"npm-run-all": "^4.1.5",
|
|
80
|
-
"prettier": "^2.
|
|
80
|
+
"prettier": "^2.6.2",
|
|
81
|
+
"qunit": "^2.19.1",
|
|
81
82
|
"qunit-dom": "^2.0.0",
|
|
82
|
-
"release-it": "^14.
|
|
83
|
+
"release-it": "^14.14.3",
|
|
83
84
|
"release-it-lerna-changelog": "^4.0.1",
|
|
84
|
-
"webpack": "^5.
|
|
85
|
+
"webpack": "^5.72.1"
|
|
85
86
|
},
|
|
86
87
|
"engines": {
|
|
87
|
-
"node": "
|
|
88
|
+
"node": "14.* || >= 16"
|
|
88
89
|
},
|
|
89
90
|
"publishConfig": {
|
|
90
91
|
"access": "public",
|
package/.husky/commit-msg
DELETED
package/RELEASE.md
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
# Release Process
|
|
2
|
-
|
|
3
|
-
Releases are mostly automated using
|
|
4
|
-
[release-it](https://github.com/release-it/release-it/) and
|
|
5
|
-
[lerna-changelog](https://github.com/lerna/lerna-changelog/).
|
|
6
|
-
|
|
7
|
-
## Preparation
|
|
8
|
-
|
|
9
|
-
Since the majority of the actual release process is automated, the primary
|
|
10
|
-
remaining task prior to releasing is confirming that all pull requests that
|
|
11
|
-
have been merged since the last release have been labeled with the appropriate
|
|
12
|
-
`lerna-changelog` labels and the titles have been updated to ensure they
|
|
13
|
-
represent something that would make sense to our users. Some great information
|
|
14
|
-
on why this is important can be found at
|
|
15
|
-
[keepachangelog.com](https://keepachangelog.com/en/1.0.0/), but the overall
|
|
16
|
-
guiding principle here is that changelogs are for humans, not machines.
|
|
17
|
-
|
|
18
|
-
When reviewing merged PR's the labels to be used are:
|
|
19
|
-
|
|
20
|
-
* breaking - Used when the PR is considered a breaking change.
|
|
21
|
-
* enhancement - Used when the PR adds a new feature or enhancement.
|
|
22
|
-
* bug - Used when the PR fixes a bug included in a previous release.
|
|
23
|
-
* documentation - Used when the PR adds or updates documentation.
|
|
24
|
-
* internal - Used for internal changes that still require a mention in the
|
|
25
|
-
changelog/release notes.
|
|
26
|
-
|
|
27
|
-
## Release
|
|
28
|
-
|
|
29
|
-
Once the prep work is completed, the actual release is straight forward:
|
|
30
|
-
|
|
31
|
-
* First, ensure that you have installed your projects dependencies:
|
|
32
|
-
|
|
33
|
-
```sh
|
|
34
|
-
yarn install
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
* Second, ensure that you have obtained a
|
|
38
|
-
[GitHub personal access token][generate-token] with the `repo` scope (no
|
|
39
|
-
other permissions are needed). Make sure the token is available as the
|
|
40
|
-
`GITHUB_AUTH` environment variable.
|
|
41
|
-
|
|
42
|
-
For instance:
|
|
43
|
-
|
|
44
|
-
```bash
|
|
45
|
-
export GITHUB_AUTH=abc123def456
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
[generate-token]: https://github.com/settings/tokens/new?scopes=repo&description=GITHUB_AUTH+env+variable
|
|
49
|
-
|
|
50
|
-
* And last (but not least 😁) do your release.
|
|
51
|
-
|
|
52
|
-
```sh
|
|
53
|
-
npx release-it
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
[release-it](https://github.com/release-it/release-it/) manages the actual
|
|
57
|
-
release process. It will prompt you to to choose the version number after which
|
|
58
|
-
you will have the chance to hand tweak the changelog to be used (for the
|
|
59
|
-
`CHANGELOG.md` and GitHub release), then `release-it` continues on to tagging,
|
|
60
|
-
pushing the tag and commits, etc.
|