Skip to content

Commit 526e69a

Browse files
committed
feat: add custom codecov
1 parent d9becfc commit 526e69a

File tree

2 files changed

+65
-8
lines changed

2 files changed

+65
-8
lines changed

.github/codecov.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
codecov:
2+
require_ci_to_pass: yes
3+
allow_coverage_offsets: True
4+
5+
coverage:
6+
precision: 2
7+
round: down
8+
range: "70...100"
9+
10+
parsers:
11+
gcov:
12+
branch_detection:
13+
conditional: yes
14+
loop: yes
15+
method: no
16+
macro: no
17+
18+
comment:
19+
layout: "reach,diff,flags,files,footer"
20+
behavior: default
21+
require_changes: no

test/browser/pages/login.test.ts

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,14 @@ describe("login", () => {
2525
// Create a fake element and set the attribute
2626
const mockElement = document.createElement("input")
2727
mockElement.setAttribute("id", "base")
28-
mockElement.setAttribute(
29-
"data-settings",
30-
'{"base":"./hello-world","csStaticBase":"./static/development/Users/jp/Dev/code-server","logLevel":2,"disableTelemetry":false,"disableUpdateCheck":false}',
31-
)
28+
const expected = {
29+
base: "./hello-world",
30+
csStaticBase: "./static/development/Users/jp/Dev/code-server",
31+
logLevel: 2,
32+
disableTelemetry: false,
33+
disableUpdateCheck: false,
34+
}
35+
mockElement.setAttribute("data-settings", JSON.stringify(expected))
3236
document.body.appendChild(mockElement)
3337
spy.mockImplementation(() => mockElement)
3438
// Load file
@@ -40,11 +44,10 @@ describe("login", () => {
4044
})
4145

4246
describe("there is no element with id 'base'", () => {
43-
let initialDom: Document
4447
beforeEach(() => {
4548
const dom = new JSDOM()
46-
initialDom = dom.window.document
4749
global.document = dom.window.document
50+
global.MutationObserver = dom.window.MutationObserver
4851

4952
const location: LocationLike = {
5053
pathname: "/healthz",
@@ -60,10 +63,43 @@ describe("login", () => {
6063
})
6164

6265
it("should not change the DOM", () => {
66+
const log = console.log
67+
const messages = []
68+
69+
console.log = (x: string) => {
70+
messages.push(x)
71+
}
72+
// Select the node that will be observed for mutations
73+
const targetNode = document.body
74+
75+
// Options for the observer (which mutations to observe)
76+
const config = { attributes: true, childList: true, subtree: true }
77+
78+
// Callback function to execute when mutations are observed
79+
const callback = function (mutationsList: any, observer: any) {
80+
// Use traditional 'for loops' for IE 11
81+
for (const mutation of mutationsList) {
82+
if (mutation.type === "childList") {
83+
console.log("A child node has been added or removed.")
84+
} else if (mutation.type === "attributes") {
85+
console.log("The " + mutation.attributeName + " attribute was modified.")
86+
}
87+
}
88+
}
89+
90+
// Create an observer instance linked to the callback function
91+
const observer = new MutationObserver(callback)
92+
93+
// Start observing the target node for configured mutations
94+
observer.observe(targetNode, config)
95+
6396
// Load file
6497
require("../../../src/browser/pages/login")
65-
const currentDom = global.document
66-
expect(initialDom).toBe(currentDom)
98+
// Nothing should have changed, which means no messages
99+
expect(messages.length).toBe(0)
100+
// Later, you can stop observing
101+
observer.disconnect()
102+
console.log = log
67103
})
68104
})
69105
})

0 commit comments

Comments
 (0)