Skip to content

Commit

Permalink
Merge pull request #605 from namecheap/chore/specify-mime-types-for-c…
Browse files Browse the repository at this point in the history
…onfig-scripts

chore(ilc): specify MIME type for configs appended by ILC
  • Loading branch information
wRLSS authored Sep 26, 2024
2 parents 4012bac + 1d8175f commit 4256a83
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 52 deletions.
48 changes: 24 additions & 24 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
ref: ""

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: ${{ matrix.branch.ref }}

Expand All @@ -36,17 +36,17 @@ jobs:
echo "BRANCH=$(git rev-parse --abbrev-ref HEAD)" >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v3

- name: Docker ILC auth
run: echo "${{ secrets.DOCKER_HUB_BROTHERS_TOKEN }}" | docker login --username brothers --password-stdin

- name: Build the Docker image
uses: docker/build-push-action@v2
uses: docker/build-push-action@v3
with:
context: ./ilc
platforms: linux/amd64,linux/arm64
Expand All @@ -62,12 +62,12 @@ jobs:
run: docker run namecheap/ilc_tmp:$SHA npm run test:ci

- name: Run server-side tests coverage
run: docker run --volume $(pwd)/artifacts/ilc/.test_output/server:/temporary namecheap/ilc_tmp:$SHA bash -c "npm run test:coverage && mv .nyc_output/* /temporary"
run: docker run --volume $(pwd)/artifacts/ilc/coverage/server:/.coverage namecheap/ilc_tmp:$SHA bash -c "npm run test:coverage && mv .nyc_output/* /.coverage"

- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.branch.name }}-server-side-tests-artifacts
path: artifacts/ilc/.test_output/server/
path: artifacts/ilc/coverage/server

- name: Build the Docker image to test client-side
run: |
Expand All @@ -78,12 +78,12 @@ jobs:
run: |
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf
sudo sysctl -p
docker run --volume $(pwd)/artifacts/ilc/.test_output/client:/temporary ilc:tmp-test-client bash -c "npm run test:client -- --browsers ChromeHeadlessWithoutSecurity && mv .karma_output/* /temporary"
docker run --volume $(pwd)/artifacts/ilc/coverage/client:/.coverage ilc:tmp-test-client bash -c "npm run test:client -- --browsers ChromeHeadlessWithoutSecurity && mv .karma_output/* /.coverage"
- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.branch.name }}-client-side-tests-artifacts
path: artifacts/ilc/.test_output/client/
path: artifacts/ilc/coverage/client

build_registry:
name: Build Registry
Expand All @@ -100,7 +100,7 @@ jobs:
ref: ""

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: ${{ matrix.branch.ref }}

Expand All @@ -112,7 +112,7 @@ jobs:

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3
with:
buildkitd-flags: --debug

Expand Down Expand Up @@ -181,7 +181,7 @@ jobs:
options: --name=postgres --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: ${{ matrix.branch.ref }}

Expand All @@ -195,7 +195,7 @@ jobs:
run: >-
bash ./registry/scripts/reset.sh;
docker run
--volume $(pwd)/artifacts/registry/.test_output:/temporary
--volume $(pwd)/artifacts/registry/coverage:/.coverage
--network ${{ job.container.network }}
-e DB_CLIENT=${{ matrix.database.client }}
-e DB_HOST=${{ matrix.database.host }}
Expand All @@ -204,12 +204,12 @@ jobs:
-e DB_PASSWORD=pwd
-e DB_NAME=$DB_NAME
namecheap/ilc_tmp:reg_$SHA
sh -c "npm run test:ci && mv .nyc_output/* /temporary"
sh -c "npm run test:ci && mv .nyc_output/* /.coverage"
- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.branch.name }}-${{ matrix.database.client }}-registry-tests-artifacts
path: artifacts/registry/.test_output/
path: ./artifacts/registry/coverage

e2e_tests:
name: Run E2E tests
Expand Down Expand Up @@ -245,10 +245,10 @@ jobs:
options: --name=postgres --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 20.8.0
cache: 'npm'
Expand All @@ -271,7 +271,7 @@ jobs:
DB_PASSWORD: pwd
DB_NAME: ilc

- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v4
if: failure()
with:
name: e2e-tests-artifacts
Expand All @@ -283,8 +283,8 @@ jobs:
needs: [build_ilc, registry_tests]
if: github.base_ref
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
- name: Create coverage report for ilc/server
id: ilc-server-coverage-report
uses: namecheap/Coverage-Diff@master
Expand Down Expand Up @@ -320,7 +320,7 @@ jobs:
postComment: false
oldCodeCoveragePath: ./dest-merged-registry-tests-artifacts/coverage/coverage-summary.json
newCodeCoveragePath: ./src-merged-registry-tests-artifacts/coverage/coverage-summary.json
total_delta: 2
total_delta: 6
- name: Compose comment
if: success() || failure()
run: |
Expand Down Expand Up @@ -377,7 +377,7 @@ jobs:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master'
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Build the Docker image
run: |
Expand Down
2 changes: 1 addition & 1 deletion ilc/client/AsyncBootUp.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default class AsyncBootUp {
return res;
}

const overridesEl = slotEl.querySelector('script[type="spa-config-override"]');
const overridesEl = slotEl.querySelector('script[type="text/spa-config-override"]');
if (overridesEl) {
const conf = JSON.parse(overridesEl.innerHTML);

Expand Down
12 changes: 6 additions & 6 deletions ilc/client/AsyncBootUp.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,15 @@ describe('async boot up', () => {
Hello! I am Body SPA.
I have SPA override config, so I should override dependencies and return my override SPA config.
</div>
<script type="spa-config-override">${JSON.stringify(config.body)}</script>
<script type="text/spa-config-override">${JSON.stringify(config.body)}</script>
</div>
<div id=${slots.footer.id}">
<div>
Hello! I am Footer SPA.
I have SPA override config, so I should return my override SPA config.
But I don't have any dependencies, so I should not override them.
</div>
<script type="spa-config-override">${JSON.stringify(config.footer)}</script>
<script type="text/spa-config-override">${JSON.stringify(config.footer)}</script>
</div>
</main>
`;
Expand Down Expand Up @@ -271,10 +271,10 @@ describe('async boot up', () => {
]);

chai.expect(document.getElementById(slots.body.id).innerHTML).does.not.include(
`<script type="spa-config-override">${JSON.stringify(config.body)}</script>`,
`<script type="text/spa-config-override">${JSON.stringify(config.body)}</script>`,
);
chai.expect(document.getElementById(slots.footer.id).innerHTML).does.not.include(
`<script type="spa-config-override">${JSON.stringify(config.footer)}</script>`,
`<script type="text/spa-config-override">${JSON.stringify(config.footer)}</script>`,
);
});

Expand Down Expand Up @@ -304,7 +304,7 @@ describe('async boot up', () => {
routing event. It means I don't have to mark myself as ready and I should not override initial
SPA config.
</div>
<script type="spa-config-override">
<script type="text/spa-config-override">
${JSON.stringify(config.footer)}
</script>
</div>
Expand All @@ -328,7 +328,7 @@ describe('async boot up', () => {
chai.expect(logger.info.called).to.be.false;

chai.expect(document.getElementById(slots.footer.id).innerHTML).includes(
`<script type="spa-config-override">${JSON.stringify(config.footer)}</script>`,
`<script type="text/spa-config-override">${JSON.stringify(config.footer)}</script>`,
);
});
});
6 changes: 3 additions & 3 deletions ilc/client/WrapApp.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,19 @@ describe('WrapApp', () => {
}

/**
* Init fake <script type="ilc-config">...</script>
* Init fake <script type="text/ilc-config">...</script>
* @param {Object} config
*/
function initFakeIlcConfig(config = {}) {
const existentIlcConfigScriptEl = document.querySelector('script[type="ilc-config"]');
const existentIlcConfigScriptEl = document.querySelector('script[type="text/ilc-config"]');

if (existentIlcConfigScriptEl) {
existentIlcConfigScriptEl.innerHTML = JSON.stringify(config);
return;
}

const ilcConfigScriptElAttr = document.createAttribute('type');
ilcConfigScriptElAttr.value = 'ilc-config';
ilcConfigScriptElAttr.value = 'text/ilc-config';

const ilcConfigScriptEl = document.createElement('script');
ilcConfigScriptEl.innerHTML = JSON.stringify(config);
Expand Down
2 changes: 1 addition & 1 deletion ilc/client/configuration/IlcConfigRoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { decodeHtmlEntities } from '../../common/utils';

export class IlcConfigRoot {
constructor() {
const ilcConfigurationNode = document.querySelector('script[type="ilc-config"]');
const ilcConfigurationNode = document.querySelector('script[type="text/ilc-config"]');

if (ilcConfigurationNode === null) {
throw new Error("Can't find single-spa configuration node. Looks like server side problem occurs.");
Expand Down
2 changes: 1 addition & 1 deletion ilc/server/tailor/configs-injector.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ module.exports = class ConfigsInjector {
dynamicLibs: registryConfig.dynamicLibs,
});

return `<script type="ilc-config">${spaConfig}</script>`;
return `<script type="text/ilc-config">${spaConfig}</script>`;
};

#getIlcState = (request) => {
Expand Down
4 changes: 2 additions & 2 deletions ilc/server/tailor/configs-injector.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ describe('configs injector', () => {
'<!-- TailorX: Ignore during parsing END -->' +
'<!-- TailorX: Ignore during parsing START -->' +
`<script type="ilc-state">${JSON.stringify(request.ilcState)}</script>` +
`<script type="ilc-config">${getSpaConfig()}</script>` +
`<script type="text/ilc-config">${getSpaConfig()}</script>` +
'<script>window.ilcApps = [];</script>' +
`<script src="${
cdnUrl + '/client.js'
Expand Down Expand Up @@ -358,7 +358,7 @@ describe('configs injector', () => {
'<html lang="en-US">' +
'<head>' +
'<!-- TailorX: Ignore during parsing START -->' +
`<script type="ilc-config">${getSpaConfig()}</script>` +
`<script type="text/ilc-config">${getSpaConfig()}</script>` +
'<script>window.ilcApps = [];</script>' +
`<script src="/_ilc/client.js" type="text/javascript" async></script>` +
browserTimingHeader +
Expand Down
4 changes: 2 additions & 2 deletions ilc/server/tailor/fragment-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ function insertStart(logger, stream, attributes, headers) {
bundleVersionOverrides,
}),
},
'insert start. Creating spa-config-override tag',
'insert start. Creating text/spa-config-override tag',
);
stream.write(`<script type="spa-config-override">${JSON.stringify(bundleVersionOverrides)}</script>`);
stream.write(`<script type="text/spa-config-override">${JSON.stringify(bundleVersionOverrides)}</script>`);
}

function insertEnd(stream, attributes, headers, index) {
Expand Down
22 changes: 11 additions & 11 deletions ilc/server/tailor/fragment-hooks.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('fragment-hooks', () => {

chai.expect(streamData).to.be.instanceOf(Buffer);
chai.expect(streamData.toString()).to.be.equal(
'<script type="spa-config-override">{"wrapperPropsOverride":{"param1":"value1","param2":"value2"}}</script>',
'<script type="text/spa-config-override">{"wrapperPropsOverride":{"param1":"value1","param2":"value2"}}</script>',
);
});

Expand All @@ -56,7 +56,7 @@ describe('fragment-hooks', () => {
chai.expect(streamData).to.be.instanceOf(Buffer);
chai.expect(streamData.toString()).to.be.equal(
'<!-- Async fragments are not fully implemented yet: https://domain.com/app.css -->' +
'<script type="spa-config-override">{"cssBundle":"https://domain.com/app.css"}</script>',
'<script type="text/spa-config-override">{"cssBundle":"https://domain.com/app.css"}</script>',
);
});

Expand All @@ -74,7 +74,7 @@ describe('fragment-hooks', () => {
chai.expect(streamData).to.be.instanceOf(Buffer);
chai.expect(streamData.toString()).to.be.equal(
'<script>(function(url, id){const link = document.head.querySelector(\'link[data-fragment-id="\' + id + \'"]\');if (link && link.href !== url) {link.href = url;}})("https://domain.com/app.css", "autogenerated_identifier");</script>' +
'<script type="spa-config-override">{"cssBundle":"https://domain.com/app.css"}</script>',
'<script type="text/spa-config-override">{"cssBundle":"https://domain.com/app.css"}</script>',
);
});

Expand Down Expand Up @@ -109,7 +109,7 @@ describe('fragment-hooks', () => {
chai.expect(streamData).to.be.instanceOf(Buffer);
chai.expect(streamData.toString()).to.be.equal(
`<script>(function(url, id){const link = document.head.querySelector('link[data-fragment-id="' + id + '"]');if (link && link.href !== url) {link.href = url;}})("${resultingUrl}", "autogenerated_identifier");</script>` +
`<script type="spa-config-override">{"cssBundle":"${resultingUrl}"}</script>`,
`<script type="text/spa-config-override">{"cssBundle":"${resultingUrl}"}</script>`,
);
});

Expand All @@ -126,7 +126,7 @@ describe('fragment-hooks', () => {

chai.expect(streamData).to.be.instanceOf(Buffer);
chai.expect(streamData.toString()).to.be.equal(
'<script type="spa-config-override">{"cssBundle":"https://domain.com/app.css"}</script>',
'<script type="text/spa-config-override">{"cssBundle":"https://domain.com/app.css"}</script>',
);
});

Expand All @@ -142,7 +142,7 @@ describe('fragment-hooks', () => {
const streamData = mockStream.read();
chai.expect(streamData).to.be.instanceOf(Buffer);
chai.expect(streamData.toString()).to.be.equal(
'<script type="spa-config-override">{"spaBundle":"https://domain.com/single_spa.js","appName":"autogenerated_identifier"}</script>',
'<script type="text/spa-config-override">{"spaBundle":"https://domain.com/single_spa.js","appName":"autogenerated_identifier"}</script>',
);
});

Expand All @@ -159,7 +159,7 @@ describe('fragment-hooks', () => {
const streamData = mockStream.read();
chai.expect(streamData).to.be.instanceOf(Buffer);
chai.expect(streamData.toString()).to.be.equal(
`<script type="spa-config-override">{"spaBundle":"${resultingUrl}","appName":"autogenerated_identifier"}</script>`,
`<script type="text/spa-config-override">{"spaBundle":"${resultingUrl}","appName":"autogenerated_identifier"}</script>`,
);
});

Expand All @@ -184,7 +184,7 @@ describe('fragment-hooks', () => {
const streamData = mockStream.read();
chai.expect(streamData).to.be.instanceOf(Buffer);
chai.expect(streamData.toString()).to.be.equal(
'<script type="spa-config-override">{"spaBundle":"https://domain.com/single_spa.js","appName":"@portal/wrapper"}</script>',
'<script type="text/spa-config-override">{"spaBundle":"https://domain.com/single_spa.js","appName":"@portal/wrapper"}</script>',
);
});

Expand All @@ -201,7 +201,7 @@ describe('fragment-hooks', () => {

chai.expect(streamData).to.be.instanceOf(Buffer);
chai.expect(streamData.toString()).to.be.equal(
'<script type="spa-config-override">{"dependencies":{"dep_name":"https://domain.com/single_spa.js"}}</script>',
'<script type="text/spa-config-override">{"dependencies":{"dep_name":"https://domain.com/single_spa.js"}}</script>',
);
});

Expand All @@ -218,7 +218,7 @@ describe('fragment-hooks', () => {

chai.expect(streamData).to.be.instanceOf(Buffer);
chai.expect(streamData.toString()).to.be.equal(
'<script type="spa-config-override">{"dependencies":{"dep_name":"https://domain.com/single_spa.js","dep_name2":"https://domain2.com/single_spa2.js"}}</script>',
'<script type="text/spa-config-override">{"dependencies":{"dep_name":"https://domain.com/single_spa.js","dep_name2":"https://domain2.com/single_spa2.js"}}</script>',
);
});

Expand All @@ -235,7 +235,7 @@ describe('fragment-hooks', () => {

chai.expect(streamData).to.be.instanceOf(Buffer);
chai.expect(streamData.toString()).to.be.equal(
'<script type="spa-config-override">{"spaBundle":"https://domain.com/single_spa.js","appName":"autogenerated_identifier"}</script>',
'<script type="text/spa-config-override">{"spaBundle":"https://domain.com/single_spa.js","appName":"autogenerated_identifier"}</script>',
);
});
});
Expand Down
Loading

0 comments on commit 4256a83

Please sign in to comment.