-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: pieh <misiek.piechowiak@gmail.com> Co-authored-by: Jude Agboola <marvinjudehk@gmail.com>
- Loading branch information
1 parent
a6ff9e9
commit 6c0316e
Showing
8 changed files
with
207 additions
and
7 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
e2e-tests/development-runtime/cypress/integration/head-function-export/scripts.js
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,20 @@ | ||
import { page } from "../../../shared-data/head-function-export.js" | ||
|
||
describe("Scripts", () => { | ||
beforeEach(() => { | ||
cy.visit(page.basic).waitForRouteChange() | ||
}) | ||
|
||
// This tests that we don't append elements to the document head more than once | ||
// A script will get called more than once it that happens | ||
it(`Inline script work and get called only once`, () => { | ||
|
||
// Head export seem to be appending the tags after waitForRouteChange() | ||
// We need to find a way to make waitForRouteChange() catch Head export too | ||
cy.wait(3000) | ||
|
||
cy.window().then(win => { | ||
expect(win.__SOME_GLOBAL_TO_CHECK_CALL_COUNT__).to.equal(1) | ||
}) | ||
}) | ||
}) |
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
20 changes: 20 additions & 0 deletions
20
e2e-tests/production-runtime/cypress/integration/head-function-export/scripts.js
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,20 @@ | ||
import { page } from "../../../shared-data/head-function-export.js" | ||
|
||
describe("Scripts", () => { | ||
beforeEach(() => { | ||
cy.visit(page.basic).waitForRouteChange() | ||
}) | ||
|
||
// This tests that we don't append elements to the document head more than once | ||
// A script will get called more than once it that happens | ||
it(`Inline script work and get called only once`, () => { | ||
|
||
// Head export seem to be appending the tags after waitForRouteChange() | ||
// We need to find a way to make waitForRouteChange() catch Head export too | ||
cy.wait(3000) | ||
|
||
cy.window().then(win => { | ||
expect(win.__SOME_GLOBAL_TO_CHECK_CALL_COUNT__).to.equal(1) | ||
}) | ||
}) | ||
}) |
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,74 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
|
||
import { diffNodes } from "../utils" | ||
|
||
function createElement( | ||
type: string, | ||
attributes: Record<string, string> | undefined = undefined, | ||
innerHTML: string | undefined = undefined | ||
): Element { | ||
const element: Element = document.createElement(type) | ||
if (attributes) { | ||
for (const [key, value] of Object.entries(attributes)) { | ||
if (value === `string`) { | ||
element.setAttribute(key, value) | ||
} | ||
} | ||
} | ||
if (innerHTML) { | ||
element.innerHTML = innerHTML | ||
} | ||
return element | ||
} | ||
|
||
describe(`diffNodes`, () => { | ||
it(`should keep same nodes, remove nodes that were not re-created, and add new nodes`, () => { | ||
const oldNodes = [ | ||
createElement(`title`, {}, `to remove`), | ||
createElement(`script`, {}, `stable`), | ||
createElement(`script`, {}, `to remove`), | ||
] | ||
|
||
const newNodes = [ | ||
createElement(`title`, {}, `to add`), | ||
createElement(`script`, {}, `stable`), | ||
createElement(`script`, {}, `to add`), | ||
] | ||
|
||
const onStale = jest.fn() | ||
const onNew = jest.fn() | ||
|
||
diffNodes({ oldNodes, newNodes, onStale, onNew }) | ||
|
||
expect(onStale.mock.calls).toMatchInlineSnapshot(` | ||
Array [ | ||
Array [ | ||
<title> | ||
to remove | ||
</title>, | ||
], | ||
Array [ | ||
<script> | ||
to remove | ||
</script>, | ||
], | ||
] | ||
`) | ||
expect(onNew.mock.calls).toMatchInlineSnapshot(` | ||
Array [ | ||
Array [ | ||
<title> | ||
to add | ||
</title>, | ||
], | ||
Array [ | ||
<script> | ||
to add | ||
</script>, | ||
], | ||
] | ||
`) | ||
}) | ||
}) |
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