-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: Adding ability to sort the import map alphabetically (#122)
* feature: Adding ability to sort the import map alphabetically * Adding readme documentation * PR feedback - Fixing test name Co-authored-by: the_mcmurder <the_mcmurder@users.noreply.github.com>
- Loading branch information
1 parent
dc040ec
commit 3f3a990
Showing
4 changed files
with
162 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
const request = require("supertest"); | ||
const { app, setConfig } = require("../src/web-server"); | ||
const { | ||
resetManifest: resetMemoryManifest, | ||
} = require("../src/io-methods/memory"); | ||
|
||
describe(`alphabetically sorted`, () => { | ||
beforeAll(() => { | ||
setConfig({ | ||
manifestFormat: "importmap", | ||
alphabetical: true, | ||
packagesViaTrailingSlashes: true, | ||
locations: { | ||
prod: "memory://prod", | ||
}, | ||
}); | ||
}); | ||
|
||
beforeEach(() => { | ||
// assure we have a clean import map every test | ||
resetMemoryManifest(); | ||
const setupRequest = request(app) | ||
.patch("/import-map.json") | ||
.query({ | ||
skip_url_check: true, | ||
}) | ||
.set("accept", "json") | ||
.send({ | ||
imports: { | ||
c: "/c-1.mjs", | ||
b: "/b-1.mjs", | ||
}, | ||
}) | ||
.expect(200) | ||
.expect("Content-Type", /json/); | ||
return setupRequest.then((response) => { | ||
expect(JSON.stringify(response.body)).toBe( | ||
`{"imports":{"b":"/b-1.mjs","c":"/c-1.mjs"},"scopes":{}}` | ||
); | ||
}); | ||
}); | ||
|
||
it(`should place the import into the map alphabetically instead of just at the end`, async () => { | ||
const response = await request(app) | ||
.patch("/services") | ||
.query({ | ||
skip_url_check: true, | ||
}) | ||
.set("accept", "json") | ||
.send({ | ||
service: "a", | ||
url: "/a-1-updated.mjs", | ||
}) | ||
.expect(200) | ||
.expect("Content-Type", /json/); | ||
|
||
expect(JSON.stringify(response.body.imports)).toBe( | ||
`{"a":"/a-1-updated.mjs","b":"/b-1.mjs","c":"/c-1.mjs"}` | ||
); | ||
}); | ||
}); | ||
|
||
describe(`not alphabetically sorted`, () => { | ||
beforeAll(() => { | ||
setConfig({ | ||
manifestFormat: "importmap", | ||
packagesViaTrailingSlashes: true, | ||
locations: { | ||
prod: "memory://prod", | ||
}, | ||
}); | ||
}); | ||
|
||
beforeEach(() => { | ||
// assure we have a clean import map every test | ||
resetMemoryManifest(); | ||
const setupRequest = request(app) | ||
.patch("/import-map.json") | ||
.query({ | ||
skip_url_check: true, | ||
}) | ||
.set("accept", "json") | ||
.send({ | ||
imports: { | ||
c: "/c-1.mjs", | ||
b: "/b-1.mjs", | ||
}, | ||
}) | ||
.expect(200) | ||
.expect("Content-Type", /json/); | ||
return setupRequest.then((response) => { | ||
expect(JSON.stringify(response.body)).toBe( | ||
`{"imports":{"c":"/c-1.mjs","b":"/b-1.mjs"},"scopes":{}}` | ||
); | ||
}); | ||
}); | ||
|
||
it(`should not place things alphabetically and should just append to the end`, async () => { | ||
const response = await request(app) | ||
.patch("/services") | ||
.query({ | ||
skip_url_check: true, | ||
}) | ||
.set("accept", "json") | ||
.send({ | ||
service: "a", | ||
url: "/a-1-updated.mjs", | ||
}) | ||
.expect(200) | ||
.expect("Content-Type", /json/); | ||
|
||
expect(JSON.stringify(response.body.imports)).toBe( | ||
`{"c":"/c-1.mjs","b":"/b-1.mjs","a":"/a-1-updated.mjs"}` | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters