This repository has been archived by the owner on May 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(module-map): missing baseUrl to module map on server (#206)
- Loading branch information
1 parent
3620a1a
commit c6a251e
Showing
9 changed files
with
102 additions
and
14 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,60 @@ | ||
/* | ||
* Copyright 2019 American Express Travel Related Services Company, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
import addBaseUrlToModuleMap from '../../../src/server/utils/addBaseUrlToModuleMap'; | ||
|
||
const moduleMap = { | ||
modules: { | ||
'module-a': { | ||
node: { | ||
url: 'https://example.com/cdn/module-a/1.0.0/module-a.node.js', | ||
integrity: '234', | ||
}, | ||
browser: { | ||
url: 'https://example.com/cdn/module-a/1.0.0/module-a.browser.js', | ||
integrity: '353', | ||
}, | ||
legacyBrowser: { | ||
url: 'https://example.com/cdn/module-a/1.0.0/module-a.legacy.browser.js', | ||
integrity: '0087', | ||
}, | ||
}, | ||
'module-b': { | ||
node: { | ||
url: 'https://example.com/cdn/module-b/1.0.0/module-b.node.js', | ||
integrity: '0322380', | ||
}, | ||
browser: { | ||
url: 'https://example.com/cdn/module-b/1.0.0/module-b.browser.js', | ||
integrity: 'sd3o23098', | ||
}, | ||
legacyBrowser: { | ||
url: 'https://example.com/cdn/module-b/1.0.0/module-b.legacy.browser.js', | ||
integrity: 'flj23032', | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
describe('addBaseUrlToModuleMap', () => { | ||
it('creates a "baseUrl" entry for each module and returns a module map including the new key', () => { | ||
const updatedModuleMap = addBaseUrlToModuleMap(moduleMap); | ||
Object.keys(updatedModuleMap.modules).forEach((moduleName) => { | ||
const module = updatedModuleMap.modules[moduleName]; | ||
expect(module.baseUrl).toBe(`https://example.com/cdn/${moduleName}/1.0.0/`); | ||
}); | ||
}); | ||
}); |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,32 @@ | ||
/* | ||
* Copyright 2020 American Express Travel Related Services Company, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
/* The baseUrl key in the module map is used by one-app-ducks to construct | ||
the language pack URL pointing at the location of the language pack */ | ||
const addBaseUrlToModuleMap = (moduleMap) => ({ | ||
...moduleMap, | ||
modules: Object.entries(moduleMap.modules).reduce((acc, [moduleName, moduleBundles]) => ( | ||
{ | ||
...acc, | ||
[moduleName]: { | ||
...moduleBundles, | ||
baseUrl: moduleBundles.node.url.replace(/[^/]+\.js$/i, ''), | ||
}, | ||
} | ||
), {}), | ||
}); | ||
|
||
export default addBaseUrlToModuleMap; |
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