Skip to content

Commit 2bc7e0b

Browse files
committed
Tests
1 parent b1c2744 commit 2bc7e0b

File tree

3 files changed

+84
-1
lines changed

3 files changed

+84
-1
lines changed

README.md

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ In your app.js or app.ts, or wherever you configure your application
1717
- import EmberResolver from 'ember-resolver';
1818
+ import EmberApp from 'ember-strict-application-resolver';
1919

20-
class TestApp extends EmberApp {
20+
class YouApp extends EmberApp {
2121
- modulePrefix = config.modulePrefix;
2222
- podModulePrefix = config.podModulePrefix;
2323
- Resolver = EmberResolver.withModules({
@@ -47,6 +47,46 @@ The type of `modules` is:
4747
};
4848
```
4949

50+
### `buildRegistry`
51+
52+
Libraries may declare `ember-strict-application-resolver` as a `dependencies` entry, and then import from `./build-registry` - to provide helpers for packages all the library's services and other things that need to be in the registry (such as from the library's dependencies as well)
53+
54+
For example:
55+
```js
56+
// in src/registry.ts (or js)
57+
import { buildRegistry } from 'ember-strict-application-resolver';
58+
import TheService from 'from-dependency/services/the-service';
59+
60+
export default buildRegistry({
61+
...import.meta.glob('./services/*', { eager: true }),
62+
'./services/the-service': { default: TheService },
63+
});
64+
```
65+
66+
Then consumers of your library would either splat this into their `modules` object:
67+
```js
68+
import libraryRegistry from 'your-library/registry';
69+
// ...
70+
71+
modules = {
72+
// if the app is using ember-strict-application-resolver
73+
...libraryRegistry(),
74+
// or if using ember-resolver
75+
...libraryRegistry('name-of-app'),
76+
}
77+
```
78+
79+
Or consuming libraries would propagate the configuration for their consumers:
80+
```js
81+
import { buildRegistry } from 'ember-strict-application-resolver';
82+
import libraryRegistry from 'your-library/registry';
83+
84+
export default buildRegistry({
85+
...import.meta.glob('./services/*', { eager: true }),
86+
// No argument should be passed here
87+
...libraryRegistry(),
88+
});
89+
```
5090

5191
## Contributing
5292

index.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<html>
2+
<head>
3+
<script type="module">window.location = '/tests'</script>
4+
</head>
5+
</html>

tests/build-registry-test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { module, test } from 'qunit';
2+
import { setupTest } from 'ember-qunit';
3+
4+
import { buildRegistry } from '#src/build-registry.ts';
5+
6+
module('buildRegistry', function (hooks) {
7+
setupTest(hooks);
8+
9+
test('returns a function', function (assert) {
10+
const result = buildRegistry({});
11+
12+
assert.strictEqual(typeof result, 'function');
13+
});
14+
15+
test('has entries', function (assert) {
16+
const result = buildRegistry({
17+
'./foo': 2,
18+
});
19+
20+
assert.deepEqual(result(), { './foo': 2 });
21+
});
22+
23+
test('entries can be prefixed', function (assert) {
24+
const result = buildRegistry({
25+
'./foo': 2,
26+
});
27+
28+
assert.deepEqual(result('test-app'), { 'test-app/foo': 2 });
29+
});
30+
31+
test('entries can be prefixed with scope', function (assert) {
32+
const result = buildRegistry({
33+
'./foo': 2,
34+
});
35+
36+
assert.deepEqual(result('@scope/test-app'), { '@scope/test-app/foo': 2 });
37+
});
38+
});

0 commit comments

Comments
 (0)