@universal-ember/test-support 0.2.0 → 0.3.1
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.
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function visitAllLinks(): Promise<
|
|
1
|
+
export declare function visitAllLinks(callback?: (url: string) => void | Promise<void>): Promise<number>;
|
|
2
2
|
//# sourceMappingURL=visit-all.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"visit-all.d.ts","sourceRoot":"","sources":["../../src/routing/visit-all.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"visit-all.d.ts","sourceRoot":"","sources":["../../src/routing/visit-all.ts"],"names":[],"mappings":"AA8CA,wBAAsB,aAAa,CACjC,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,mBAgFjD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-service.js","sources":["../../src/container/get-service.ts"],"sourcesContent":["import { assert } from '@ember/debug';\nimport type { Registry as ServiceRegistry } from '@ember/service';\nimport { getContext } from '@ember/test-helpers';\nimport { getOwner } from '@ember/owner';\nimport type Owner from '@ember/owner';\n\nexport function getService<ServiceName extends keyof ServiceRegistry>(\n name: ServiceName,\n): ServiceRegistry[ServiceName] {\n const context = getContext() as { owner?: Owner } | undefined;\n assert('Could not determine the context for the test', context);\n\n const owner = context.owner || getOwner(context);\n assert('Could not find the owner on the context', owner);\n\n const service = owner.lookup(`service:${name}`);\n\n return service;\n}\n"],"names":["getService","name","context","getContext","assert","owner","getOwner","service","lookup"],"mappings":";;;;AAMO,SAASA,UAAUA,CACxBC,IAAiB,EACa;AAC9B,EAAA,MAAMC,OAAO,GAAGC,UAAU,EAAmC
|
|
1
|
+
{"version":3,"file":"get-service.js","sources":["../../src/container/get-service.ts"],"sourcesContent":["import { assert } from '@ember/debug';\nimport type { Registry as ServiceRegistry } from '@ember/service';\nimport { getContext } from '@ember/test-helpers';\nimport { getOwner } from '@ember/owner';\nimport type Owner from '@ember/owner';\n\nexport function getService<ServiceName extends keyof ServiceRegistry>(\n name: ServiceName,\n): ServiceRegistry[ServiceName] {\n const context = getContext() as { owner?: Owner } | undefined;\n assert('Could not determine the context for the test', context);\n\n const owner = context.owner || getOwner(context);\n assert('Could not find the owner on the context', owner);\n\n const service = owner.lookup(`service:${name}`);\n\n return service;\n}\n"],"names":["getService","name","context","getContext","assert","owner","getOwner","service","lookup"],"mappings":";;;;AAMO,SAASA,UAAUA,CACxBC,IAAiB,EACa;AAC9B,EAAA,MAAMC,OAAO,GAAGC,UAAU,EAAmC;AAC7DC,EAAAA,MAAM,CAAC,8CAA8C,EAAEF,OAAO,CAAC;EAE/D,MAAMG,KAAK,GAAGH,OAAO,CAACG,KAAK,IAAIC,QAAQ,CAACJ,OAAO,CAAC;AAChDE,EAAAA,MAAM,CAAC,yCAAyC,EAAEC,KAAK,CAAC;EAExD,MAAME,OAAO,GAAGF,KAAK,CAACG,MAAM,CAAC,CAAA,QAAA,EAAWP,IAAI,CAAA,CAAE,CAAC;AAE/C,EAAA,OAAOM,OAAO;AAChB;;;;"}
|
|
@@ -3,10 +3,25 @@ import { visit, getContext, currentURL, find, click, findAll } from '@ember/test
|
|
|
3
3
|
import QUnit from 'qunit';
|
|
4
4
|
|
|
5
5
|
function findInAppLinks() {
|
|
6
|
-
|
|
6
|
+
const results = [];
|
|
7
|
+
const allAnchorsOnThePage = findAll('a');
|
|
8
|
+
for (const a of allAnchorsOnThePage) {
|
|
9
|
+
const href = a.getAttribute('href');
|
|
10
|
+
if (!href) continue;
|
|
11
|
+
if (href.startsWith('http')) continue;
|
|
12
|
+
const current = new URL(currentURL(), window.location.origin);
|
|
13
|
+
const url = new URL(href, current);
|
|
14
|
+
const withoutDomain = `${url.pathname}${url.search}${url.hash}`;
|
|
15
|
+
results.push({
|
|
16
|
+
href: withoutDomain,
|
|
17
|
+
original: href,
|
|
18
|
+
selector: `a[href="${href}"]`
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return results;
|
|
7
22
|
}
|
|
8
23
|
const assert = QUnit.assert;
|
|
9
|
-
async function visitAllLinks() {
|
|
24
|
+
async function visitAllLinks(callback) {
|
|
10
25
|
/**
|
|
11
26
|
* string of "on::target"
|
|
12
27
|
*/
|
|
@@ -21,7 +36,7 @@ async function visitAllLinks() {
|
|
|
21
36
|
while (queue.length > 0) {
|
|
22
37
|
const toVisit = queue.shift();
|
|
23
38
|
assert$1(`Queue entries cannot be falsey`, toVisit);
|
|
24
|
-
if (
|
|
39
|
+
if ('changeReturnTo' in toVisit) {
|
|
25
40
|
returnTo = toVisit.changeReturnTo;
|
|
26
41
|
continue;
|
|
27
42
|
}
|
|
@@ -29,10 +44,10 @@ async function visitAllLinks() {
|
|
|
29
44
|
// In-page links are on the page we're already on.
|
|
30
45
|
// As long as we haven't already encountered an error,
|
|
31
46
|
// this is silly to check.
|
|
32
|
-
if (toVisit.startsWith('#')) {
|
|
47
|
+
if (toVisit.original.startsWith('#')) {
|
|
33
48
|
continue;
|
|
34
49
|
}
|
|
35
|
-
const [nonHashPart] = toVisit.split('#');
|
|
50
|
+
const [nonHashPart] = toVisit.href.split('#');
|
|
36
51
|
|
|
37
52
|
// This was our first page, we've already been here
|
|
38
53
|
if (nonHashPart === '/') {
|
|
@@ -40,23 +55,27 @@ async function visitAllLinks() {
|
|
|
40
55
|
}
|
|
41
56
|
const key = `${currentURL()}::${nonHashPart}`;
|
|
42
57
|
if (visited.has(key)) continue;
|
|
43
|
-
const result = router.recognize(toVisit);
|
|
58
|
+
const result = router.recognize(toVisit.href);
|
|
44
59
|
if (!result) {
|
|
45
|
-
assert.ok(true, `${toVisit} on page ${returnTo} is not recognized by this app and will be skipped`);
|
|
60
|
+
assert.ok(true, `${toVisit.href} on page ${returnTo} is not recognized by this app and will be skipped`);
|
|
46
61
|
continue;
|
|
47
62
|
}
|
|
48
63
|
await visit(returnTo);
|
|
49
|
-
const link = find(
|
|
50
|
-
assert$1(`link exists
|
|
64
|
+
const link = find(toVisit.selector);
|
|
65
|
+
assert$1(`link exists via selector \`${toVisit.selector}\``, link);
|
|
51
66
|
await click(link);
|
|
52
|
-
assert.ok(currentURL().startsWith(toVisit), `Navigation was successful: to:${toVisit}, from:${returnTo}`);
|
|
67
|
+
assert.ok(currentURL().startsWith(toVisit.href), `Navigation was successful: to:${toVisit.original}, from:${returnTo}`);
|
|
53
68
|
visited.add(key);
|
|
69
|
+
if (callback) {
|
|
70
|
+
await callback(toVisit.href);
|
|
71
|
+
}
|
|
54
72
|
const links = findInAppLinks();
|
|
55
73
|
queue.push({
|
|
56
74
|
changeReturnTo: currentURL()
|
|
57
75
|
});
|
|
58
76
|
queue.push(...links);
|
|
59
77
|
}
|
|
78
|
+
return visited.size;
|
|
60
79
|
}
|
|
61
80
|
|
|
62
81
|
export { visitAllLinks };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"visit-all.js","sources":["../../src/routing/visit-all.ts"],"sourcesContent":["import { assert as debugAssert } from '@ember/debug';\nimport {\n visit,\n find,\n getContext,\n click,\n currentURL,\n findAll,\n} from '@ember/test-helpers';\nimport QUnit from 'qunit';\nimport type Owner from '@ember/owner';\nimport type RouterService from '@ember/routing/router-service';\n\nfunction findInAppLinks():
|
|
1
|
+
{"version":3,"file":"visit-all.js","sources":["../../src/routing/visit-all.ts"],"sourcesContent":["import { assert as debugAssert } from '@ember/debug';\nimport {\n visit,\n find,\n getContext,\n click,\n currentURL,\n findAll,\n} from '@ember/test-helpers';\nimport QUnit from 'qunit';\nimport type Owner from '@ember/owner';\nimport type RouterService from '@ember/routing/router-service';\n\ninterface InAppLink {\n href: string;\n original: string;\n selector: string;\n}\n\nfunction findInAppLinks(): InAppLink[] {\n const results: InAppLink[] = [];\n\n const allAnchorsOnThePage = findAll('a');\n\n for (const a of allAnchorsOnThePage) {\n const href = a.getAttribute('href');\n\n if (!href) continue;\n if (href.startsWith('http')) continue;\n\n const current = new URL(currentURL(), window.location.origin);\n const url = new URL(href, current);\n const withoutDomain = `${url.pathname}${url.search}${url.hash}`;\n\n results.push({\n href: withoutDomain,\n original: href,\n selector: `a[href=\"${href}\"]`,\n });\n }\n\n return results;\n}\n\nconst assert = QUnit.assert;\n\nexport async function visitAllLinks(\n callback?: (url: string) => void | Promise<void>,\n) {\n /**\n * string of \"on::target\"\n */\n const visited = new Set();\n let returnTo = '/';\n\n await visit(returnTo);\n\n const inAppLinks = findInAppLinks();\n const queue: (InAppLink | { changeReturnTo: string })[] = [...inAppLinks];\n\n const ctx = getContext() as unknown as { owner: Owner };\n const router = ctx?.owner?.lookup('service:router') as RouterService;\n\n debugAssert(`Could not find the router service`, router);\n\n while (queue.length > 0) {\n const toVisit = queue.shift();\n\n debugAssert(`Queue entries cannot be falsey`, toVisit);\n\n if ('changeReturnTo' in toVisit) {\n returnTo = toVisit.changeReturnTo;\n continue;\n }\n\n // In-page links are on the page we're already on.\n // As long as we haven't already encountered an error,\n // this is silly to check.\n if (toVisit.original.startsWith('#')) {\n continue;\n }\n\n const [nonHashPart] = toVisit.href.split('#');\n\n // This was our first page, we've already been here\n if (nonHashPart === '/') {\n continue;\n }\n\n const key = `${currentURL()}::${nonHashPart}`;\n\n if (visited.has(key)) continue;\n\n const result = router.recognize(toVisit.href);\n\n if (!result) {\n assert.ok(\n true,\n `${toVisit.href} on page ${returnTo} is not recognized by this app and will be skipped`,\n );\n continue;\n }\n\n await visit(returnTo);\n\n const link = find(toVisit.selector);\n\n debugAssert(`link exists via selector \\`${toVisit.selector}\\``, link);\n\n await click(link);\n assert.ok(\n currentURL().startsWith(toVisit.href),\n `Navigation was successful: to:${toVisit.original}, from:${returnTo}`,\n );\n visited.add(key);\n\n if (callback) {\n await callback(toVisit.href);\n }\n\n const links = findInAppLinks();\n\n queue.push({ changeReturnTo: currentURL() });\n queue.push(...links);\n }\n\n return visited.size;\n}\n"],"names":["findInAppLinks","results","allAnchorsOnThePage","findAll","a","href","getAttribute","startsWith","current","URL","currentURL","window","location","origin","url","withoutDomain","pathname","search","hash","push","original","selector","assert","QUnit","visitAllLinks","callback","visited","Set","returnTo","visit","inAppLinks","queue","ctx","getContext","router","owner","lookup","debugAssert","length","toVisit","shift","changeReturnTo","nonHashPart","split","key","has","result","recognize","ok","link","find","click","add","links","size"],"mappings":";;;;AAmBA,SAASA,cAAcA,GAAgB;EACrC,MAAMC,OAAoB,GAAG,EAAE;AAE/B,EAAA,MAAMC,mBAAmB,GAAGC,OAAO,CAAC,GAAG,CAAC;AAExC,EAAA,KAAK,MAAMC,CAAC,IAAIF,mBAAmB,EAAE;AACnC,IAAA,MAAMG,IAAI,GAAGD,CAAC,CAACE,YAAY,CAAC,MAAM,CAAC;IAEnC,IAAI,CAACD,IAAI,EAAE;AACX,IAAA,IAAIA,IAAI,CAACE,UAAU,CAAC,MAAM,CAAC,EAAE;AAE7B,IAAA,MAAMC,OAAO,GAAG,IAAIC,GAAG,CAACC,UAAU,EAAE,EAAEC,MAAM,CAACC,QAAQ,CAACC,MAAM,CAAC;IAC7D,MAAMC,GAAG,GAAG,IAAIL,GAAG,CAACJ,IAAI,EAAEG,OAAO,CAAC;AAClC,IAAA,MAAMO,aAAa,GAAG,CAAGD,EAAAA,GAAG,CAACE,QAAQ,CAAA,EAAGF,GAAG,CAACG,MAAM,CAAA,EAAGH,GAAG,CAACI,IAAI,CAAE,CAAA;IAE/DjB,OAAO,CAACkB,IAAI,CAAC;AACXd,MAAAA,IAAI,EAAEU,aAAa;AACnBK,MAAAA,QAAQ,EAAEf,IAAI;MACdgB,QAAQ,EAAE,WAAWhB,IAAI,CAAA,EAAA;AAC3B,KAAC,CAAC;AACJ;AAEA,EAAA,OAAOJ,OAAO;AAChB;AAEA,MAAMqB,MAAM,GAAGC,KAAK,CAACD,MAAM;AAEpB,eAAeE,aAAaA,CACjCC,QAAgD,EAChD;AACA;AACF;AACA;AACE,EAAA,MAAMC,OAAO,G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EACJ,CAAA,EAAGT,OAAO,CAAClC,IAAI,CAAA,SAAA,EAAYuB,QAAQ,CAAA,kDAAA,CACrC,CAAC;AACD,MAAA;AACF;IAEA,MAAMC,KAAK,CAACD,QAAQ,CAAC;AAErB,IAAA,MAAMqB,IAAI,GAAGC,IAAI,CAACX,OAAO,CAAClB,QAAQ,CAAC;IAEnCgB,QAAW,CAAC,8BAA8BE,OAAO,CAAClB,QAAQ,CAAI,EAAA,CAAA,EAAE4B,IAAI,CAAC;IAErE,MAAME,KAAK,CAACF,IAAI,CAAC;IACjB3B,MAAM,CAAC0B,EAAE,CACPtC,UAAU,EAAE,CAACH,UAAU,CAACgC,OAAO,CAAClC,IAAI,CAAC,EACrC,CAAiCkC,8BAAAA,EAAAA,OAAO,CAACnB,QAAQ,CAAA,OAAA,EAAUQ,QAAQ,CAAA,CACrE,CAAC;AACDF,IAAAA,OAAO,CAAC0B,GAAG,CAACR,GAAG,CAAC;AAEhB,IAAA,IAAInB,QAAQ,EAAE;AACZ,MAAA,MAAMA,QAAQ,CAACc,OAAO,CAAClC,IAAI,CAAC;AAC9B;AAEA,IAAA,MAAMgD,KAAK,GAAGrD,cAAc,EAAE;IAE9B+B,KAAK,CAACZ,IAAI,CAAC;MAAEsB,cAAc,EAAE/B,UAAU;AAAG,KAAC,CAAC;AAC5CqB,IAAAA,KAAK,CAACZ,IAAI,CAAC,GAAGkC,KAAK,CAAC;AACtB;EAEA,OAAO3B,OAAO,CAAC4B,IAAI;AACrB;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@universal-ember/test-support",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "The default blueprint for Embroider v2 addons.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ember-addon"
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"dist"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@ember/test-helpers": "^
|
|
35
|
+
"@ember/test-helpers": "^4.0.4",
|
|
36
36
|
"@embroider/addon-shim": "^1.8.7",
|
|
37
37
|
"decorator-transforms": "^1.0.1"
|
|
38
38
|
},
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
"@typescript-eslint/parser": "^6.14.0",
|
|
74
74
|
"babel-plugin-ember-template-compilation": "^2.2.1",
|
|
75
75
|
"concurrently": "^8.2.2",
|
|
76
|
-
"ember-template-lint": "^
|
|
76
|
+
"ember-template-lint": "^6.0.0",
|
|
77
77
|
"eslint": "^8.56.0",
|
|
78
78
|
"eslint-config-prettier": "^9.1.0",
|
|
79
79
|
"eslint-plugin-ember": "^11.12.0",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"prettier": "^3.1.1",
|
|
83
83
|
"prettier-plugin-ember-template-tag": "^1.1.0",
|
|
84
84
|
"qunit": "^2.20.1",
|
|
85
|
-
"rollup": "^4.
|
|
85
|
+
"rollup": "^4.24.4",
|
|
86
86
|
"rollup-plugin-copy": "^3.5.0",
|
|
87
87
|
"typescript": "^5.3.3"
|
|
88
88
|
},
|
|
@@ -99,6 +99,7 @@
|
|
|
99
99
|
"app-js": {}
|
|
100
100
|
},
|
|
101
101
|
"peerDependencies": {
|
|
102
|
+
"ember-source": ">= 3.28",
|
|
102
103
|
"qunit": "^2.20.1"
|
|
103
104
|
},
|
|
104
105
|
"scripts": {
|