scopes.json (6344B)
1 { 2 "importMapBaseURL": "https://example.com/app/index.html", 3 "tests": { 4 "Fallback to toplevel and between scopes": { 5 "importMap": { 6 "imports": { 7 "a": "/a-1.mjs", 8 "b": "/b-1.mjs", 9 "c": "/c-1.mjs", 10 "d": "/d-1.mjs" 11 }, 12 "scopes": { 13 "/scope2/": { 14 "a": "/a-2.mjs", 15 "d": "/d-2.mjs" 16 }, 17 "/scope2/scope3/": { 18 "b": "/b-3.mjs", 19 "d": "/d-3.mjs" 20 } 21 } 22 }, 23 "tests": { 24 "should fall back to `imports` when no scopes match": { 25 "baseURL": "https://example.com/scope1/foo.mjs", 26 "expectedResults": { 27 "a": "https://example.com/a-1.mjs", 28 "b": "https://example.com/b-1.mjs", 29 "c": "https://example.com/c-1.mjs", 30 "d": "https://example.com/d-1.mjs" 31 } 32 }, 33 "should use a direct scope override": { 34 "baseURL": "https://example.com/scope2/foo.mjs", 35 "expectedResults": { 36 "a": "https://example.com/a-2.mjs", 37 "b": "https://example.com/b-1.mjs", 38 "c": "https://example.com/c-1.mjs", 39 "d": "https://example.com/d-2.mjs" 40 } 41 }, 42 "should use an indirect scope override": { 43 "baseURL": "https://example.com/scope2/scope3/foo.mjs", 44 "expectedResults": { 45 "a": "https://example.com/a-2.mjs", 46 "b": "https://example.com/b-3.mjs", 47 "c": "https://example.com/c-1.mjs", 48 "d": "https://example.com/d-3.mjs" 49 } 50 } 51 } 52 }, 53 "Relative URL scope keys": { 54 "importMap": { 55 "imports": { 56 "a": "/a-1.mjs", 57 "b": "/b-1.mjs", 58 "c": "/c-1.mjs" 59 }, 60 "scopes": { 61 "": { 62 "a": "/a-empty-string.mjs" 63 }, 64 "./": { 65 "b": "/b-dot-slash.mjs" 66 }, 67 "../": { 68 "c": "/c-dot-dot-slash.mjs" 69 } 70 } 71 }, 72 "tests": { 73 "An empty string scope is a scope with import map base URL": { 74 "baseURL": "https://example.com/app/index.html", 75 "expectedResults": { 76 "a": "https://example.com/a-empty-string.mjs", 77 "b": "https://example.com/b-dot-slash.mjs", 78 "c": "https://example.com/c-dot-dot-slash.mjs" 79 } 80 }, 81 "'./' scope is a scope with import map base URL's directory": { 82 "baseURL": "https://example.com/app/foo.mjs", 83 "expectedResults": { 84 "a": "https://example.com/a-1.mjs", 85 "b": "https://example.com/b-dot-slash.mjs", 86 "c": "https://example.com/c-dot-dot-slash.mjs" 87 } 88 }, 89 "'../' scope is a scope with import map base URL's parent directory": { 90 "baseURL": "https://example.com/foo.mjs", 91 "expectedResults": { 92 "a": "https://example.com/a-1.mjs", 93 "b": "https://example.com/b-1.mjs", 94 "c": "https://example.com/c-dot-dot-slash.mjs" 95 } 96 } 97 } 98 }, 99 "Package-like scenarios": { 100 "importMap": { 101 "imports": { 102 "moment": "/node_modules/moment/src/moment.js", 103 "moment/": "/node_modules/moment/src/", 104 "lodash-dot": "./node_modules/lodash-es/lodash.js", 105 "lodash-dot/": "./node_modules/lodash-es/", 106 "lodash-dotdot": "../node_modules/lodash-es/lodash.js", 107 "lodash-dotdot/": "../node_modules/lodash-es/" 108 }, 109 "scopes": { 110 "/": { 111 "moment": "/node_modules_3/moment/src/moment.js", 112 "vue": "/node_modules_3/vue/dist/vue.runtime.esm.js" 113 }, 114 "/js/": { 115 "lodash-dot": "./node_modules_2/lodash-es/lodash.js", 116 "lodash-dot/": "./node_modules_2/lodash-es/", 117 "lodash-dotdot": "../node_modules_2/lodash-es/lodash.js", 118 "lodash-dotdot/": "../node_modules_2/lodash-es/" 119 } 120 } 121 }, 122 "tests": { 123 "Base URLs inside the scope should use the scope if the scope has matching keys": { 124 "baseURL": "https://example.com/js/app.mjs", 125 "expectedResults": { 126 "lodash-dot": "https://example.com/app/node_modules_2/lodash-es/lodash.js", 127 "lodash-dot/foo": "https://example.com/app/node_modules_2/lodash-es/foo", 128 "lodash-dotdot": "https://example.com/node_modules_2/lodash-es/lodash.js", 129 "lodash-dotdot/foo": "https://example.com/node_modules_2/lodash-es/foo" 130 } 131 }, 132 "Base URLs inside the scope fallback to less specific scope": { 133 "baseURL": "https://example.com/js/app.mjs", 134 "expectedResults": { 135 "moment": "https://example.com/node_modules_3/moment/src/moment.js", 136 "vue": "https://example.com/node_modules_3/vue/dist/vue.runtime.esm.js" 137 } 138 }, 139 "Base URLs inside the scope fallback to toplevel": { 140 "baseURL": "https://example.com/js/app.mjs", 141 "expectedResults": { 142 "moment/foo": "https://example.com/node_modules/moment/src/foo" 143 } 144 }, 145 "Base URLs outside a scope shouldn't use the scope even if the scope has matching keys": { 146 "baseURL": "https://example.com/app.mjs", 147 "expectedResults": { 148 "lodash-dot": "https://example.com/app/node_modules/lodash-es/lodash.js", 149 "lodash-dotdot": "https://example.com/node_modules/lodash-es/lodash.js", 150 "lodash-dot/foo": "https://example.com/app/node_modules/lodash-es/foo", 151 "lodash-dotdot/foo": "https://example.com/node_modules/lodash-es/foo" 152 } 153 }, 154 "Fallback to toplevel or not, depending on trailing slash match": { 155 "baseURL": "https://example.com/app.mjs", 156 "expectedResults": { 157 "moment": "https://example.com/node_modules_3/moment/src/moment.js", 158 "moment/foo": "https://example.com/node_modules/moment/src/foo" 159 } 160 }, 161 "should still fail for package-like specifiers that are not declared": { 162 "baseURL": "https://example.com/js/app.mjs", 163 "expectedResults": { 164 "underscore/": null, 165 "underscore/foo": null 166 } 167 } 168 } 169 } 170 } 171 }