@bagaar/ember-graphql-mocking 0.10.0 → 0.11.2

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 CHANGED
@@ -1,24 +1,38 @@
1
+ # Changelog
1
2
 
3
+ ## Release (2025-02-05)
2
4
 
5
+ @bagaar/ember-graphql-mocking 0.11.1 (patch)
3
6
 
7
+ #### :house: Internal
8
+ * Other
9
+ * [#198](https://github.com/Bagaar/ember-graphql-mocking/pull/198) Set up Release Plan ([@bertdeblock](https://github.com/bertdeblock))
10
+ * `@bagaar/ember-graphql-mocking`
11
+ * [#197](https://github.com/Bagaar/ember-graphql-mocking/pull/197) Update `release-it` setup ([@bertdeblock](https://github.com/bertdeblock))
4
12
 
13
+ #### Committers: 1
14
+ - Bert De Block ([@bertdeblock](https://github.com/bertdeblock))
5
15
 
16
+ ## v0.11.0 (2024-03-06)
6
17
 
18
+ #### :boom: Breaking Change
19
+ * [#196](https://github.com/Bagaar/ember-graphql-mocking/pull/196) Convert to v2 addon ([@bertdeblock](https://github.com/bertdeblock))
7
20
 
8
-
21
+ #### Committers: 1
22
+ - Bert De Block ([@bertdeblock](https://github.com/bertdeblock))
9
23
 
10
24
  ## v0.10.0 (2024-02-08)
11
25
 
12
26
  #### :boom: Breaking Change
13
- * [#195](https://github.com/Bagaar/ember-graphql-mocking/pull/195) Remove automatic inclusion/exclusion of msw's worker file ([@bertdeblock](https://github.com/bertdeblock))
14
- * [#194](https://github.com/Bagaar/ember-graphql-mocking/pull/194) Convert to TS ([@bertdeblock](https://github.com/bertdeblock))
15
- * [#193](https://github.com/Bagaar/ember-graphql-mocking/pull/193) Don't leak msw `worker.start` return value ([@bertdeblock](https://github.com/bertdeblock))
27
+ * [#195](https://github.com/bagaar/ember-graphql-mocking/pull/195) Remove automatic inclusion/exclusion of msw's worker file ([@bertdeblock](https://github.com/bertdeblock))
28
+ * [#194](https://github.com/bagaar/ember-graphql-mocking/pull/194) Convert to TS ([@bertdeblock](https://github.com/bertdeblock))
29
+ * [#193](https://github.com/bagaar/ember-graphql-mocking/pull/193) Don't leak msw `worker.start` return value ([@bertdeblock](https://github.com/bertdeblock))
16
30
 
17
31
  #### :rocket: Enhancement
18
- * [#194](https://github.com/Bagaar/ember-graphql-mocking/pull/194) Convert to TS ([@bertdeblock](https://github.com/bertdeblock))
32
+ * [#194](https://github.com/bagaar/ember-graphql-mocking/pull/194) Convert to TS ([@bertdeblock](https://github.com/bertdeblock))
19
33
 
20
34
  #### :bug: Bug Fix
21
- * [#193](https://github.com/Bagaar/ember-graphql-mocking/pull/193) Don't leak msw `worker.start` return value ([@bertdeblock](https://github.com/bertdeblock))
35
+ * [#193](https://github.com/bagaar/ember-graphql-mocking/pull/193) Don't leak msw `worker.start` return value ([@bertdeblock](https://github.com/bertdeblock))
22
36
 
23
37
  #### Committers: 1
24
38
  - Bert De Block ([@bertdeblock](https://github.com/bertdeblock))
@@ -26,16 +40,16 @@
26
40
  ## v0.9.0 (2023-11-27)
27
41
 
28
42
  #### :boom: Breaking Change
29
- * [#191](https://github.com/Bagaar/ember-graphql-mocking/pull/191) Support MSW v2 ([@bertdeblock](https://github.com/bertdeblock))
30
- * [#189](https://github.com/Bagaar/ember-graphql-mocking/pull/189) Drop support for Ember v4.4 ([@bertdeblock](https://github.com/bertdeblock))
31
- * [#177](https://github.com/Bagaar/ember-graphql-mocking/pull/177) Drop support for Node.js v16 ([@bertdeblock](https://github.com/bertdeblock))
43
+ * [#191](https://github.com/bagaar/ember-graphql-mocking/pull/191) Support MSW v2 ([@bertdeblock](https://github.com/bertdeblock))
44
+ * [#189](https://github.com/bagaar/ember-graphql-mocking/pull/189) Drop support for Ember v4.4 ([@bertdeblock](https://github.com/bertdeblock))
45
+ * [#177](https://github.com/bagaar/ember-graphql-mocking/pull/177) Drop support for Node.js v16 ([@bertdeblock](https://github.com/bertdeblock))
32
46
 
33
47
  #### :rocket: Enhancement
34
- * [#191](https://github.com/Bagaar/ember-graphql-mocking/pull/191) Support MSW v2 ([@bertdeblock](https://github.com/bertdeblock))
48
+ * [#191](https://github.com/bagaar/ember-graphql-mocking/pull/191) Support MSW v2 ([@bertdeblock](https://github.com/bertdeblock))
35
49
 
36
50
  #### :house: Internal
37
- * [#176](https://github.com/Bagaar/ember-graphql-mocking/pull/176) Update dependencies ([@bertdeblock](https://github.com/bertdeblock))
38
- * [#175](https://github.com/Bagaar/ember-graphql-mocking/pull/175) Update to Ember v5.4 ([@bertdeblock](https://github.com/bertdeblock))
51
+ * [#176](https://github.com/bagaar/ember-graphql-mocking/pull/176) Update dependencies ([@bertdeblock](https://github.com/bertdeblock))
52
+ * [#175](https://github.com/bagaar/ember-graphql-mocking/pull/175) Update to Ember v5.4 ([@bertdeblock](https://github.com/bertdeblock))
39
53
 
40
54
  #### Committers: 1
41
55
  - Bert De Block ([@bertdeblock](https://github.com/bertdeblock))
@@ -43,7 +57,7 @@
43
57
  ## v0.8.0 (2023-07-06)
44
58
 
45
59
  #### :boom: Breaking Change
46
- * [#143](https://github.com/Bagaar/ember-graphql-mocking/pull/143) Drop support for Ember versions below v4.4 and Node v14 ([@bertdeblock](https://github.com/bertdeblock))
60
+ * [#143](https://github.com/bagaar/ember-graphql-mocking/pull/143) Drop support for Ember versions below v4.4 and Node v14 ([@bertdeblock](https://github.com/bertdeblock))
47
61
 
48
62
  #### Committers: 1
49
63
  - Bert De Block ([@bertdeblock](https://github.com/bertdeblock))
@@ -51,14 +65,14 @@
51
65
  ## v0.7.0 (2023-02-22)
52
66
 
53
67
  #### :boom: Breaking Change
54
- * [#104](https://github.com/Bagaar/ember-graphql-mocking/pull/104) Update `msw` to v1 and make it a peer dependency ([@gvdp](https://github.com/gvdp))
68
+ * [#104](https://github.com/bagaar/ember-graphql-mocking/pull/104) Update `msw` to v1 and make it a peer dependency ([@gvdp](https://github.com/gvdp))
55
69
 
56
70
  #### :rocket: Enhancement
57
- * [#104](https://github.com/Bagaar/ember-graphql-mocking/pull/104) Update `msw` to v1 and make it a peer dependency ([@gvdp](https://github.com/gvdp))
58
- * [#100](https://github.com/Bagaar/ember-graphql-mocking/pull/100) Speed up requiring `index.js` file ([@bertdeblock](https://github.com/bertdeblock))
71
+ * [#104](https://github.com/bagaar/ember-graphql-mocking/pull/104) Update `msw` to v1 and make it a peer dependency ([@gvdp](https://github.com/gvdp))
72
+ * [#100](https://github.com/bagaar/ember-graphql-mocking/pull/100) Speed up requiring `index.js` file ([@bertdeblock](https://github.com/bertdeblock))
59
73
 
60
74
  #### :memo: Documentation
61
- * [#106](https://github.com/Bagaar/ember-graphql-mocking/pull/106) Update compatibility and installation section ([@bertdeblock](https://github.com/bertdeblock))
75
+ * [#106](https://github.com/bagaar/ember-graphql-mocking/pull/106) Update compatibility and installation section ([@bertdeblock](https://github.com/bertdeblock))
62
76
 
63
77
  #### Committers: 2
64
78
  - Bert De Block ([@bertdeblock](https://github.com/bertdeblock))
@@ -67,12 +81,12 @@
67
81
  ## v0.6.0 (2022-09-05)
68
82
 
69
83
  #### :boom: Breaking Change
70
- * [#38](https://github.com/Bagaar/ember-graphql-mocking/pull/38) Make `setupEmberGraphqlMocking` async ([@bertdeblock](https://github.com/bertdeblock))
71
- * [#37](https://github.com/Bagaar/ember-graphql-mocking/pull/37) Update `graphql` and `msw` dependencies ([@bertdeblock](https://github.com/bertdeblock))
72
- * [#34](https://github.com/Bagaar/ember-graphql-mocking/pull/34) Update `msw` to v0.43.0 ([@bertdeblock](https://github.com/bertdeblock))
84
+ * [#38](https://github.com/bagaar/ember-graphql-mocking/pull/38) Make `setupEmberGraphqlMocking` async ([@bertdeblock](https://github.com/bertdeblock))
85
+ * [#37](https://github.com/bagaar/ember-graphql-mocking/pull/37) Update `graphql` and `msw` dependencies ([@bertdeblock](https://github.com/bertdeblock))
86
+ * [#34](https://github.com/bagaar/ember-graphql-mocking/pull/34) Update `msw` to v0.43.0 ([@bertdeblock](https://github.com/bertdeblock))
73
87
 
74
88
  #### :bug: Bug Fix
75
- * [#38](https://github.com/Bagaar/ember-graphql-mocking/pull/38) Make `setupEmberGraphqlMocking` async ([@bertdeblock](https://github.com/bertdeblock))
89
+ * [#38](https://github.com/bagaar/ember-graphql-mocking/pull/38) Make `setupEmberGraphqlMocking` async ([@bertdeblock](https://github.com/bertdeblock))
76
90
 
77
91
  #### Committers: 1
78
92
  - Bert De Block ([@bertdeblock](https://github.com/bertdeblock))
@@ -80,9 +94,9 @@
80
94
  ## v0.5.0 (2022-06-24)
81
95
 
82
96
  #### :boom: Breaking Change
83
- * [#29](https://github.com/Bagaar/ember-graphql-mocking/pull/29) Update `msw` to v0.42.3 ([@bertdeblock](https://github.com/bertdeblock))
84
- * [#27](https://github.com/Bagaar/ember-graphql-mocking/pull/27) Drop support for Ember v3.24 ([@bertdeblock](https://github.com/bertdeblock))
85
- * [#26](https://github.com/Bagaar/ember-graphql-mocking/pull/26) Drop support for Node v12 ([@bertdeblock](https://github.com/bertdeblock))
97
+ * [#29](https://github.com/bagaar/ember-graphql-mocking/pull/29) Update `msw` to v0.42.3 ([@bertdeblock](https://github.com/bertdeblock))
98
+ * [#27](https://github.com/bagaar/ember-graphql-mocking/pull/27) Drop support for Ember v3.24 ([@bertdeblock](https://github.com/bertdeblock))
99
+ * [#26](https://github.com/bagaar/ember-graphql-mocking/pull/26) Drop support for Node v12 ([@bertdeblock](https://github.com/bertdeblock))
86
100
 
87
101
  #### Committers: 1
88
102
  - Bert De Block ([@bertdeblock](https://github.com/bertdeblock))
@@ -90,13 +104,13 @@
90
104
  ## v0.4.1 (2022-02-09)
91
105
 
92
106
  #### :bug: Bug Fix
93
- * [#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))
107
+ * [#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))
94
108
 
95
109
  #### :memo: Documentation
96
- * [#19](https://github.com/Bagaar/ember-graphql-mocking/pull/19) Fix install command in docs ([@bertdeblock](https://github.com/bertdeblock))
110
+ * [#19](https://github.com/bagaar/ember-graphql-mocking/pull/19) Fix install command in docs ([@bertdeblock](https://github.com/bertdeblock))
97
111
 
98
112
  #### :house: Internal
99
- * [#22](https://github.com/Bagaar/ember-graphql-mocking/pull/22) Don't publish `.husky` folder and `RELEASE.md` file ([@bertdeblock](https://github.com/bertdeblock))
113
+ * [#22](https://github.com/bagaar/ember-graphql-mocking/pull/22) Don't publish `.husky` folder and `RELEASE.md` file ([@bertdeblock](https://github.com/bertdeblock))
100
114
 
101
115
  #### Committers: 1
102
116
  - Bert De Block ([@bertdeblock](https://github.com/bertdeblock))
@@ -104,7 +118,7 @@
104
118
  ## v0.4.0 (2022-02-03)
105
119
 
106
120
  #### :rocket: Enhancement
107
- * [#18](https://github.com/Bagaar/ember-graphql-mocking/pull/18) Make `msw` start options configurable ([@bertdeblock](https://github.com/bertdeblock))
121
+ * [#18](https://github.com/bagaar/ember-graphql-mocking/pull/18) Make `msw` start options configurable ([@bertdeblock](https://github.com/bertdeblock))
108
122
 
109
123
  #### Committers: 1
110
124
  - Bert De Block ([@bertdeblock](https://github.com/bertdeblock))
@@ -112,7 +126,7 @@
112
126
  ## v0.3.2 (2022-02-02)
113
127
 
114
128
  #### :house: Internal
115
- * [#17](https://github.com/Bagaar/ember-graphql-mocking/pull/17) Fix release commit message ([@bertdeblock](https://github.com/bertdeblock))
129
+ * [#17](https://github.com/bagaar/ember-graphql-mocking/pull/17) Fix release commit message ([@bertdeblock](https://github.com/bertdeblock))
116
130
 
117
131
  #### Committers: 1
118
132
  - Bert De Block ([@bertdeblock](https://github.com/bertdeblock))
@@ -121,7 +135,7 @@
121
135
  ## v0.3.1 (2022-02-02)
122
136
 
123
137
  #### :house: Internal
124
- * [#16](https://github.com/Bagaar/ember-graphql-mocking/pull/16) Update publish config ([@bertdeblock](https://github.com/bertdeblock))
138
+ * [#16](https://github.com/bagaar/ember-graphql-mocking/pull/16) Update publish config ([@bertdeblock](https://github.com/bertdeblock))
125
139
 
126
140
  #### Committers: 1
127
141
  - Bert De Block ([@bertdeblock](https://github.com/bertdeblock))
@@ -130,8 +144,7 @@
130
144
  ## v0.2.2 (2022-02-02)
131
145
 
132
146
  #### :house: Internal
133
- * [#14](https://github.com/Bagaar/ember-graphql-mocking/pull/14) Release setup ([@bertdeblock](https://github.com/bertdeblock))
147
+ * [#14](https://github.com/bagaar/ember-graphql-mocking/pull/14) Release setup ([@bertdeblock](https://github.com/bertdeblock))
134
148
 
135
149
  #### Committers: 1
136
150
  - Bert De Block ([@bertdeblock](https://github.com/bertdeblock))
137
-
package/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2021
3
+ Copyright (c) Bagaar NV
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
6
 
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # Ember GraphQL Mocking
1
+ # @bagaar/ember-graphql-mocking
2
2
 
3
- [![CI](https://github.com/Bagaar/ember-graphql-mocking/workflows/CI/badge.svg)](https://github.com/Bagaar/ember-graphql-mocking/actions?query=workflow%3ACI)
3
+ [![CI](https://github.com/bagaar/ember-graphql-mocking/workflows/CI/badge.svg)](https://github.com/bagaar/ember-graphql-mocking/actions?query=workflow%3ACI)
4
4
  [![NPM Version](https://badge.fury.io/js/%40bagaar%2Fember-graphql-mocking.svg)](https://badge.fury.io/js/%40bagaar%2Fember-graphql-mocking)
5
5
 
6
6
  Ember addon for mocking GraphQL requests using [Mock Service Worker (MSW)](https://github.com/mswjs/msw).
@@ -8,8 +8,7 @@ Ember addon for mocking GraphQL requests using [Mock Service Worker (MSW)](https
8
8
  ## Compatibility
9
9
 
10
10
  - Ember.js v4.8 or above
11
- - Ember CLI v4.8 or above
12
- - Node.js v18 or above
11
+ - Embroider or ember-auto-import v2
13
12
  - MSW v2 or above
14
13
 
15
14
  ## Installation
@@ -28,7 +27,7 @@ yarn add -D @bagaar/ember-graphql-mocking msw
28
27
 
29
28
  ## Usage
30
29
 
31
- ### 1. Set up Ember GraphQL Mocking
30
+ ### 1. Set up @bagaar/ember-graphql-mocking
32
31
 
33
32
  In `tests/test-helper.js`:
34
33
  1. Import `setupEmberGraphqlMocking`
@@ -93,7 +92,7 @@ import { visit, currentURL } from '@ember/test-helpers';
93
92
  import { setupApplicationTest } from 'my-app/tests/helpers';
94
93
  import { mockResolvers, setupGraphqlTest } from '@bagaar/ember-graphql-mocking/test-support'; // 1.
95
94
 
96
- module('Acceptance | ember graphql mocking', function (hooks) {
95
+ module('Acceptance | ember-graphql-mocking', function (hooks) {
97
96
  setupApplicationTest(hooks);
98
97
  setupGraphqlTest(hooks); // 2.
99
98
 
@@ -121,7 +120,7 @@ module('Acceptance | ember graphql mocking', function (hooks) {
121
120
  > Calling `mockResolvers` multiple times within a single test, will simply merge all resolvers into a single root.
122
121
 
123
122
  > [!NOTE]
124
- > Working versions of these code examples can be found in [this addon's `tests` folder](./tests/).
123
+ > Working versions of these code examples can be found in [this addon's test app](./test-app/).
125
124
 
126
125
  ## Contributing
127
126
 
package/addon-main.cjs ADDED
@@ -0,0 +1,4 @@
1
+ 'use strict';
2
+
3
+ const { addonV1Shim } = require('@embroider/addon-shim');
4
+ module.exports = addonV1Shim(__dirname);
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ export default interface Registry {
2
+ }
3
+ //# sourceMappingURL=template-registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"template-registry.d.ts","sourceRoot":"","sources":["../src/template-registry.ts"],"names":[],"mappings":"AAQA,MAAM,CAAC,OAAO,WAAW,QAAQ;CAEhC"}
@@ -1,13 +1,18 @@
1
- import { type setupApplicationTest } from 'ember-qunit';
2
1
  import { type DocumentNode } from 'graphql';
3
2
  import { type SetupWorker, type StartOptions } from 'msw/browser';
4
3
  interface Options {
5
4
  mswStartOptions: StartOptions;
6
5
  }
6
+ type Hooks = {
7
+ after(fn: () => void | Promise<void>): void;
8
+ afterEach(fn: () => void | Promise<void>): void;
9
+ before(fn: () => void | Promise<void>): void;
10
+ beforeEach(fn: () => void | Promise<void>): void;
11
+ };
7
12
  export declare function setupEmberGraphqlMocking(schemaDocument: DocumentNode, providedOptions?: Options): Promise<void>;
8
- export declare function setupGraphqlTest(hooks: Parameters<typeof setupApplicationTest>[0]): void;
13
+ export declare function setupGraphqlTest(hooks: Hooks): void;
9
14
  export declare function mockResolvers(resolvers: object): void;
10
15
  export declare function getWorker(): SetupWorker;
11
- export declare function destroyWorker(): void;
16
+ export declare function stopWorker(): void;
12
17
  export {};
13
18
  //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/test-support/index.ts"],"names":[],"mappings":"AACA,OAAO,EAA2B,KAAK,YAAY,EAAE,MAAM,SAAS,CAAC;AAErE,OAAO,EAAe,KAAK,WAAW,EAAE,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AAE/E,UAAU,OAAO;IACf,eAAe,EAAE,YAAY,CAAC;CAC/B;AAID,KAAK,KAAK,GAAG;IACX,KAAK,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAC5C,SAAS,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAChD,MAAM,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAC7C,UAAU,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;CAClD,CAAC;AAmBF,wBAAsB,wBAAwB,CAC5C,cAAc,EAAE,YAAY,EAC5B,eAAe,CAAC,EAAE,OAAO,iBAK1B;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,KAAK,QAsB5C;AAED,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,QAO9C;AAED,wBAAgB,SAAS,gBAOxB;AAED,wBAAgB,UAAU,SAOzB"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=template-registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"template-registry.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,103 @@
1
+ import { assert } from '@ember/debug';
2
+ import { buildASTSchema, graphql as graphql$1 } from 'graphql';
3
+ import { graphql, HttpResponse } from 'msw';
4
+ import { setupWorker } from 'msw/browser';
5
+
6
+ const IS_TESTEM = Boolean(window.Testem);
7
+ const DEFAULT_OPTIONS = {
8
+ mswStartOptions: {
9
+ quiet: IS_TESTEM,
10
+ serviceWorker: {
11
+ options: {
12
+ scope: IS_TESTEM ? window.location.pathname : '/tests'
13
+ }
14
+ }
15
+ }
16
+ };
17
+ let isSetupGraphqlTestCalled = false;
18
+ let root = null;
19
+ let worker = null;
20
+ let options = null;
21
+ async function setupEmberGraphqlMocking(schemaDocument, providedOptions) {
22
+ options = {
23
+ ...DEFAULT_OPTIONS,
24
+ ...providedOptions
25
+ };
26
+ createWorker();
27
+ createGraphqlOperationHandler(schemaDocument);
28
+ }
29
+ function setupGraphqlTest(hooks) {
30
+ assert('Cannot call `setupGraphqlTest` without providing the `hooks` argument. Please make sure to call `setupGraphqlTest(hooks);`.', hooks);
31
+ hooks.before(() => {
32
+ isSetupGraphqlTestCalled = true;
33
+ });
34
+ hooks.after(() => {
35
+ isSetupGraphqlTestCalled = false;
36
+ });
37
+ hooks.beforeEach(async () => {
38
+ await startWorker(options?.mswStartOptions || {});
39
+ });
40
+ hooks.afterEach(() => {
41
+ stopWorker();
42
+ clearRoot();
43
+ });
44
+ }
45
+ function mockResolvers(resolvers) {
46
+ assert('Cannot call `mockResolvers` before calling `setupGraphqlTest`. Please make sure to call `setupGraphqlTest(hooks);`.', isSetupGraphqlTestCalled);
47
+ root = {
48
+ ...root,
49
+ ...resolvers
50
+ };
51
+ }
52
+ function getWorker() {
53
+ assert('Cannot call `getWorker` before calling `setupEmberGraphqlMocking`. Please make sure to call `setupEmberGraphqlMocking(yourSchemaDocument[, yourProvidedOptions]);`.', worker);
54
+ return worker;
55
+ }
56
+ function stopWorker() {
57
+ assert('Cannot call `destroyWorker` before calling `setupEmberGraphqlMocking`. Please make sure to call `setupEmberGraphqlMocking(yourSchemaDocument[, yourProvidedOptions]);`.', worker);
58
+ worker.stop();
59
+ }
60
+ function createWorker() {
61
+ worker = setupWorker();
62
+ }
63
+ function createGraphqlOperationHandler(schemaDocument) {
64
+ assert('[BUG] `worker` is not set.', worker);
65
+ const schema = buildASTSchema(schemaDocument);
66
+ const graphqlOperation = graphql.operation(async ({
67
+ request
68
+ }) => {
69
+ const {
70
+ query,
71
+ variables
72
+ } = (await request.json()) || {
73
+ query: '',
74
+ variables: {}
75
+ };
76
+ const {
77
+ data,
78
+ errors
79
+ } = await graphql$1({
80
+ rootValue: root,
81
+ schema,
82
+ source: query,
83
+ variableValues: variables
84
+ });
85
+
86
+ // @ts-expect-error latest versions of msw return a type which is ObjMap<unknown> | null | undefined, which seems incompatible with the .json() method
87
+ return HttpResponse.json({
88
+ data,
89
+ errors
90
+ });
91
+ });
92
+ worker.use(graphqlOperation);
93
+ }
94
+ async function startWorker(mswStartOptions) {
95
+ assert('[BUG] `worker` is not set.', worker);
96
+ await worker.start(mswStartOptions);
97
+ }
98
+ function clearRoot() {
99
+ root = null;
100
+ }
101
+
102
+ export { getWorker, mockResolvers, setupEmberGraphqlMocking, setupGraphqlTest, stopWorker };
103
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../src/test-support/index.ts"],"sourcesContent":["import { assert } from '@ember/debug';\nimport { buildASTSchema, graphql, type DocumentNode } from 'graphql';\nimport { graphql as mswGraphql, HttpResponse } from 'msw';\nimport { setupWorker, type SetupWorker, type StartOptions } from 'msw/browser';\n\ninterface Options {\n mswStartOptions: StartOptions;\n}\n\ntype WindowWithTestem = typeof window & { Testem: unknown };\n\ntype Hooks = {\n after(fn: () => void | Promise<void>): void;\n afterEach(fn: () => void | Promise<void>): void;\n before(fn: () => void | Promise<void>): void;\n beforeEach(fn: () => void | Promise<void>): void;\n};\n\nconst IS_TESTEM = Boolean((window as WindowWithTestem).Testem);\nconst DEFAULT_OPTIONS: Options = {\n mswStartOptions: {\n quiet: IS_TESTEM,\n serviceWorker: {\n options: {\n scope: IS_TESTEM ? window.location.pathname : '/tests',\n },\n },\n },\n};\n\nlet isSetupGraphqlTestCalled = false;\nlet root: object | null = null;\nlet worker: SetupWorker | null = null;\nlet options: Options | null = null;\n\nexport async function setupEmberGraphqlMocking(\n schemaDocument: DocumentNode,\n providedOptions?: Options,\n) {\n options = { ...DEFAULT_OPTIONS, ...providedOptions };\n createWorker();\n createGraphqlOperationHandler(schemaDocument);\n}\n\nexport function setupGraphqlTest(hooks: Hooks) {\n assert(\n 'Cannot call `setupGraphqlTest` without providing the `hooks` argument. Please make sure to call `setupGraphqlTest(hooks);`.',\n hooks,\n );\n\n hooks.before(() => {\n isSetupGraphqlTestCalled = true;\n });\n\n hooks.after(() => {\n isSetupGraphqlTestCalled = false;\n });\n\n hooks.beforeEach(async () => {\n await startWorker(options?.mswStartOptions || {});\n });\n\n hooks.afterEach(() => {\n stopWorker();\n clearRoot();\n });\n}\n\nexport function mockResolvers(resolvers: object) {\n assert(\n 'Cannot call `mockResolvers` before calling `setupGraphqlTest`. Please make sure to call `setupGraphqlTest(hooks);`.',\n isSetupGraphqlTestCalled,\n );\n\n root = { ...root, ...resolvers };\n}\n\nexport function getWorker() {\n assert(\n 'Cannot call `getWorker` before calling `setupEmberGraphqlMocking`. Please make sure to call `setupEmberGraphqlMocking(yourSchemaDocument[, yourProvidedOptions]);`.',\n worker,\n );\n\n return worker;\n}\n\nexport function stopWorker() {\n assert(\n 'Cannot call `destroyWorker` before calling `setupEmberGraphqlMocking`. Please make sure to call `setupEmberGraphqlMocking(yourSchemaDocument[, yourProvidedOptions]);`.',\n worker,\n );\n\n worker.stop();\n}\n\nfunction createWorker() {\n worker = setupWorker();\n}\n\nfunction createGraphqlOperationHandler(schemaDocument: DocumentNode) {\n assert('[BUG] `worker` is not set.', worker);\n\n const schema = buildASTSchema(schemaDocument);\n const graphqlOperation = mswGraphql.operation(async ({ request }) => {\n const { query, variables } = (await request.json()) || {\n query: '',\n variables: {},\n };\n\n const { data, errors } = await graphql({\n rootValue: root,\n schema,\n source: query,\n variableValues: variables,\n });\n\n // @ts-expect-error latest versions of msw return a type which is ObjMap<unknown> | null | undefined, which seems incompatible with the .json() method\n return HttpResponse.json({ data, errors });\n });\n\n worker.use(graphqlOperation);\n}\n\nasync function startWorker(mswStartOptions: Options['mswStartOptions']) {\n assert('[BUG] `worker` is not set.', worker);\n\n await worker.start(mswStartOptions);\n}\n\nfunction clearRoot() {\n root = null;\n}\n"],"names":["IS_TESTEM","Boolean","window","Testem","DEFAULT_OPTIONS","mswStartOptions","quiet","serviceWorker","options","scope","location","pathname","isSetupGraphqlTestCalled","root","worker","setupEmberGraphqlMocking","schemaDocument","providedOptions","createWorker","createGraphqlOperationHandler","setupGraphqlTest","hooks","assert","before","after","beforeEach","startWorker","afterEach","stopWorker","clearRoot","mockResolvers","resolvers","getWorker","stop","setupWorker","schema","buildASTSchema","graphqlOperation","mswGraphql","operation","request","query","variables","json","data","errors","graphql","rootValue","source","variableValues","HttpResponse","use","start"],"mappings":"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"}
package/package.json CHANGED
@@ -1,152 +1,115 @@
1
1
  {
2
2
  "name": "@bagaar/ember-graphql-mocking",
3
- "version": "0.10.0",
3
+ "version": "0.11.2",
4
4
  "description": "Ember addon for mocking GraphQL requests using Mock Service Worker (MSW).",
5
5
  "keywords": [
6
- "ember-addon"
6
+ "ember-addon",
7
+ "graphql",
8
+ "msw"
7
9
  ],
8
- "repository": "https://github.com/Bagaar/ember-graphql-mocking",
10
+ "repository": "https://github.com/bagaar/ember-graphql-mocking",
9
11
  "license": "MIT",
10
12
  "author": "Bagaar",
13
+ "exports": {
14
+ ".": {
15
+ "types": "./declarations/index.d.ts",
16
+ "default": "./dist/index.js"
17
+ },
18
+ "./*": {
19
+ "types": "./declarations/*.d.ts",
20
+ "default": "./dist/*.js"
21
+ },
22
+ "./addon-main.js": "./addon-main.cjs",
23
+ "./test-support": {
24
+ "types": "./declarations/test-support/index.d.ts",
25
+ "default": "./dist/test-support/index.js"
26
+ }
27
+ },
11
28
  "typesVersions": {
12
29
  "*": {
13
30
  "test-support": [
14
- "declarations/addon-test-support/index.d.ts"
15
- ],
16
- "test-support/*": [
17
- "declarations/addon-test-support/*",
18
- "declarations/addon-test-support/*/index.d.ts"
31
+ "declarations/test-support/index.d.ts"
19
32
  ],
20
33
  "*": [
21
- "declarations/addon/*",
22
- "declarations/addon/*/index.d.ts"
34
+ "declarations/*"
23
35
  ]
24
36
  }
25
37
  },
26
- "directories": {
27
- "doc": "doc",
28
- "test": "tests"
29
- },
38
+ "files": [
39
+ "addon-main.cjs",
40
+ "CHANGELOG.md",
41
+ "declarations",
42
+ "dist"
43
+ ],
30
44
  "scripts": {
31
- "build": "ember build --environment=production",
32
- "lint": "concurrently \"npm:lint:*(!fix)\" --names \"lint:\"",
33
- "lint:css": "stylelint \"**/*.css\"",
34
- "lint:css:fix": "concurrently \"npm:lint:css -- --fix\"",
35
- "lint:fix": "concurrently \"npm:lint:*:fix\" --names \"fix:\"",
36
- "lint:hbs": "ember-template-lint .",
37
- "lint:hbs:fix": "ember-template-lint . --fix",
45
+ "build": "concurrently 'npm:build:*'",
46
+ "build:js": "rollup --config",
47
+ "build:types": "glint --declaration",
48
+ "lint": "concurrently 'npm:lint:*(!fix)' --names 'lint:'",
49
+ "lint:fix": "concurrently 'npm:lint:*:fix' --names 'fix:'",
50
+ "lint:hbs": "ember-template-lint . --no-error-on-unmatched-pattern",
51
+ "lint:hbs:fix": "ember-template-lint . --fix --no-error-on-unmatched-pattern",
38
52
  "lint:js": "eslint . --cache",
39
53
  "lint:js:fix": "eslint . --fix",
40
- "lint:types": "tsc --noEmit",
41
- "prepack": "tsc --project tsconfig.declarations.json",
42
- "postpack": "rimraf declarations",
43
- "prepare": "husky install",
44
- "start": "ember serve",
45
- "test": "concurrently \"npm:lint\" \"npm:test:*\" --names \"lint,test:\"",
46
- "test:ember": "ember test",
47
- "test:ember-compatibility": "ember try:each"
48
- },
49
- "commitlint": {
50
- "extends": [
51
- "@commitlint/config-conventional"
52
- ]
54
+ "lint:types": "glint",
55
+ "prepack": "rollup --config",
56
+ "start": "concurrently 'npm:start:*'",
57
+ "start:js": "rollup --config --watch --no-watch.clearScreen",
58
+ "start:types": "glint --declaration --watch",
59
+ "test": "echo 'A v2 addon does not have tests, run tests in test-app'"
53
60
  },
54
61
  "dependencies": {
55
- "@babel/core": "^7.23.3",
56
- "ember-auto-import": "^2.7.0",
57
- "ember-cli-babel": "^8.2.0",
58
- "lodash.merge": "^4.6.2"
62
+ "@embroider/addon-shim": "^1.8.7",
63
+ "decorator-transforms": "^1.0.1"
59
64
  },
60
65
  "devDependencies": {
61
- "@apollo/client": "^3.9.4",
62
- "@commitlint/cli": "^18.4.3",
63
- "@commitlint/config-conventional": "^18.4.3",
64
- "@ember/optional-features": "^2.0.0",
65
- "@ember/test-helpers": "^3.2.1",
66
- "@embroider/test-setup": "^3.0.3",
67
- "@glimmer/component": "^1.1.2",
68
- "@glimmer/tracking": "^1.1.2",
69
- "@release-it-plugins/lerna-changelog": "^6.0.0",
70
- "@tsconfig/ember": "^3.0.3",
71
- "@types/lodash.merge": "^4.6.9",
72
- "@types/qunit": "^2.19.10",
73
- "@types/rsvp": "^4.0.9",
74
- "@typescript-eslint/eslint-plugin": "^6.19.1",
75
- "@typescript-eslint/parser": "^6.19.1",
76
- "broccoli-asset-rev": "^3.0.0",
66
+ "@babel/core": "^7.23.6",
67
+ "@babel/plugin-transform-typescript": "^7.23.6",
68
+ "@babel/runtime": "^7.17.0",
69
+ "@embroider/addon-dev": "^4.1.0",
70
+ "@glint/core": "^1.2.1",
71
+ "@glint/environment-ember-loose": "^1.2.1",
72
+ "@glint/environment-ember-template-imports": "^1.2.1",
73
+ "@glint/template": "^1.2.1",
74
+ "@rollup/plugin-babel": "^6.0.4",
75
+ "@tsconfig/ember": "^3.0.2",
76
+ "@typescript-eslint/eslint-plugin": "^6.14.0",
77
+ "@typescript-eslint/parser": "^6.14.0",
78
+ "babel-plugin-ember-template-compilation": "^2.2.1",
77
79
  "concurrently": "^8.2.2",
78
- "ember-cli": "~5.6.0",
79
- "ember-cli-clean-css": "^3.0.0",
80
- "ember-cli-dependency-checker": "^3.3.2",
81
- "ember-cli-htmlbars": "^6.3.0",
82
- "ember-cli-inject-live-reload": "^2.1.0",
83
- "ember-cli-sri": "^2.1.1",
84
- "ember-cli-terser": "^4.0.2",
85
- "ember-load-initializers": "^2.1.2",
86
- "ember-page-title": "^8.2.0",
87
- "ember-qunit": "^8.0.2",
88
- "ember-resolver": "^11.0.1",
89
80
  "ember-source": "~5.6.0",
90
- "ember-source-channel-url": "^3.0.0",
91
81
  "ember-template-lint": "^5.13.0",
92
- "ember-try": "^3.0.0",
93
82
  "eslint": "^8.56.0",
94
83
  "eslint-config-prettier": "^9.1.0",
95
- "eslint-plugin-ember": "^12.0.0",
96
- "eslint-plugin-n": "^16.6.2",
97
- "eslint-plugin-prettier": "^5.1.3",
98
- "eslint-plugin-qunit": "^8.0.1",
84
+ "eslint-plugin-ember": "^11.12.0",
85
+ "eslint-plugin-n": "^16.4.0",
86
+ "eslint-plugin-prettier": "^5.0.1",
99
87
  "graphql": "^16.8.1",
100
- "husky": "^9.0.10",
101
- "loader.js": "^4.7.0",
102
- "msw": "^2.0.9",
103
- "prettier": "^3.2.4",
104
- "qunit": "^2.20.0",
105
- "qunit-dom": "^3.0.0",
106
- "release-it": "^17.0.3",
107
- "rimraf": "^5.0.1",
108
- "stylelint": "^16.2.1",
109
- "stylelint-config-standard": "^36.0.0",
110
- "stylelint-prettier": "^5.0.0",
111
- "typescript": "^5.3.3",
112
- "webpack": "^5.89.0"
88
+ "msw": "^2.7.0",
89
+ "prettier": "^3.1.1",
90
+ "prettier-plugin-ember-template-tag": "^1.1.0",
91
+ "rollup": "^4.9.1",
92
+ "rollup-plugin-copy": "^3.5.0",
93
+ "typescript": "^5.3.3"
113
94
  },
114
95
  "peerDependencies": {
115
- "ember-qunit": "^8.0.0",
116
96
  "ember-source": ">= 4.8.0",
117
- "graphql": "^16.0.0",
118
- "msw": "^2.0.0"
119
- },
120
- "engines": {
121
- "node": ">= 18"
97
+ "graphql": ">= 16.0.0",
98
+ "msw": ">= 2.0.0"
122
99
  },
123
100
  "publishConfig": {
124
- "access": "public",
125
101
  "registry": "https://registry.npmjs.org"
126
102
  },
127
103
  "ember": {
128
104
  "edition": "octane"
129
105
  },
130
106
  "ember-addon": {
131
- "configPath": "tests/dummy/config"
132
- },
133
- "msw": {
134
- "workerDirectory": "tests/dummy/public"
107
+ "version": 2,
108
+ "type": "addon",
109
+ "main": "addon-main.cjs",
110
+ "app-js": {}
135
111
  },
136
- "release-it": {
137
- "plugins": {
138
- "@release-it-plugins/lerna-changelog": {
139
- "infile": "CHANGELOG.md",
140
- "launchEditor": false
141
- }
142
- },
143
- "git": {
144
- "commitMessage": "chore(release): ${version}",
145
- "tagName": "v${version}"
146
- },
147
- "github": {
148
- "release": true,
149
- "tokenRef": "GITHUB_AUTH"
150
- }
112
+ "volta": {
113
+ "extends": "../package.json"
151
114
  }
152
115
  }
@@ -1,125 +0,0 @@
1
- import { assert } from '@ember/debug';
2
- import { type setupApplicationTest } from 'ember-qunit';
3
- import { buildASTSchema, graphql, type DocumentNode } from 'graphql';
4
- import merge from 'lodash.merge';
5
- import { graphql as mswGraphql, HttpResponse } from 'msw';
6
- import { setupWorker, type SetupWorker, type StartOptions } from 'msw/browser';
7
-
8
- interface Options {
9
- mswStartOptions: StartOptions;
10
- }
11
-
12
- type WindowWithTestem = typeof window & { Testem: unknown };
13
-
14
- const IS_TESTEM = Boolean((window as WindowWithTestem).Testem);
15
- const DEFAULT_OPTIONS: Options = {
16
- mswStartOptions: {
17
- quiet: IS_TESTEM,
18
- serviceWorker: {
19
- options: {
20
- scope: IS_TESTEM ? window.location.pathname : '/tests',
21
- },
22
- },
23
- },
24
- };
25
-
26
- let isSetupGraphqlTestCalled = false;
27
- let root: object | null = null;
28
- let worker: SetupWorker | null = null;
29
-
30
- export async function setupEmberGraphqlMocking(
31
- schemaDocument: DocumentNode,
32
- providedOptions?: Options,
33
- ) {
34
- const options = merge({}, DEFAULT_OPTIONS, providedOptions);
35
-
36
- createWorker();
37
- createGraphqlOperationHandler(schemaDocument);
38
-
39
- await startWorker(options.mswStartOptions);
40
- }
41
-
42
- export function setupGraphqlTest(
43
- hooks: Parameters<typeof setupApplicationTest>[0],
44
- ) {
45
- assert(
46
- 'Cannot call `setupGraphqlTest` without providing the `hooks` argument. Please make sure to call `setupGraphqlTest(hooks);`.',
47
- hooks,
48
- );
49
-
50
- hooks.before(() => {
51
- isSetupGraphqlTestCalled = true;
52
- });
53
-
54
- hooks.after(() => {
55
- isSetupGraphqlTestCalled = false;
56
- });
57
-
58
- hooks.afterEach(clearRoot);
59
- }
60
-
61
- export function mockResolvers(resolvers: object) {
62
- assert(
63
- 'Cannot call `mockResolvers` before calling `setupGraphqlTest`. Please make sure to call `setupGraphqlTest(hooks);`.',
64
- isSetupGraphqlTestCalled,
65
- );
66
-
67
- root = { ...root, ...resolvers };
68
- }
69
-
70
- export function getWorker() {
71
- assert(
72
- 'Cannot call `getWorker` before calling `setupEmberGraphqlMocking`. Please make sure to call `setupEmberGraphqlMocking(yourSchemaDocument[, yourProvidedOptions]);`.',
73
- worker,
74
- );
75
-
76
- return worker;
77
- }
78
-
79
- export function destroyWorker() {
80
- assert(
81
- 'Cannot call `destroyWorker` before calling `setupEmberGraphqlMocking`. Please make sure to call `setupEmberGraphqlMocking(yourSchemaDocument[, yourProvidedOptions]);`.',
82
- worker,
83
- );
84
-
85
- worker.stop();
86
-
87
- worker = null;
88
- }
89
-
90
- function createWorker() {
91
- worker = setupWorker();
92
- }
93
-
94
- function createGraphqlOperationHandler(schemaDocument: DocumentNode) {
95
- assert('[BUG] `worker` is not set.', worker);
96
-
97
- const schema = buildASTSchema(schemaDocument);
98
- const graphqlOperation = mswGraphql.operation(async ({ request }) => {
99
- const { query, variables } = (await request.json()) || {
100
- query: '',
101
- variables: {},
102
- };
103
-
104
- const { data, errors } = await graphql({
105
- rootValue: root,
106
- schema,
107
- source: query,
108
- variableValues: variables,
109
- });
110
-
111
- return HttpResponse.json({ data, errors });
112
- });
113
-
114
- worker.use(graphqlOperation);
115
- }
116
-
117
- async function startWorker(mswStartOptions: Options['mswStartOptions']) {
118
- assert('[BUG] `worker` is not set.', worker);
119
-
120
- await worker.start(mswStartOptions);
121
- }
122
-
123
- function clearRoot() {
124
- root = null;
125
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../addon-test-support/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAA2B,KAAK,YAAY,EAAE,MAAM,SAAS,CAAC;AAGrE,OAAO,EAAe,KAAK,WAAW,EAAE,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AAE/E,UAAU,OAAO;IACf,eAAe,EAAE,YAAY,CAAC;CAC/B;AAoBD,wBAAsB,wBAAwB,CAC5C,cAAc,EAAE,YAAY,EAC5B,eAAe,CAAC,EAAE,OAAO,iBAQ1B;AAED,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC,CAAC,CAAC,QAgBlD;AAED,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,QAO9C;AAED,wBAAgB,SAAS,gBAOxB;AAED,wBAAgB,aAAa,SAS5B"}
package/index.js DELETED
@@ -1,11 +0,0 @@
1
- 'use strict';
2
-
3
- module.exports = {
4
- name: require('./package').name,
5
-
6
- options: {
7
- 'ember-cli-babel': {
8
- enableTypeScriptTransform: true,
9
- },
10
- },
11
- };