-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from IslamZaoui/dev
add unit testing & update CI workflow
- Loading branch information
Showing
11 changed files
with
127 additions
and
13 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
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
test-results | ||
node_modules | ||
|
||
# Output | ||
|
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,25 @@ | ||
import { expect, test } from '@playwright/test'; | ||
|
||
test('home page has expected headers', async ({ page }) => { | ||
const response = await page.goto('/'); | ||
if (response) { | ||
const headers = await response.allHeaders(); | ||
expect(headers).toHaveProperty('access-control-allow-origin'); | ||
expect(headers).toHaveProperty('content-security-policy'); | ||
expect(headers).toHaveProperty('permissions-policy'); | ||
expect(headers).toHaveProperty('x-content-type-options'); | ||
expect(headers).toHaveProperty('x-frame-options'); | ||
} else { | ||
throw new Error('Failed to load the home page'); | ||
} | ||
}); | ||
|
||
test('home page have removed headers', async ({ page }) => { | ||
const response = await page.goto('/'); | ||
if (response) { | ||
const headers = await response.allHeaders(); | ||
expect(headers).not.toHaveProperty('x-sveltekit-page'); | ||
} else { | ||
throw new Error('Failed to load the home page'); | ||
} | ||
}); |
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,10 @@ | ||
import { defineConfig } from '@playwright/test'; | ||
|
||
export default defineConfig({ | ||
webServer: { | ||
command: 'bun run build && bun run preview', | ||
port: 4173 | ||
}, | ||
|
||
testDir: 'e2e' | ||
}); |
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 |
---|---|---|
|
@@ -4,6 +4,8 @@ | |
"scripts": { | ||
"build": "turbo run build", | ||
"dev": "turbo run dev", | ||
"preview": "turbo run preview", | ||
"test": "turbo run test", | ||
"release": "turbo run build && changeset publish", | ||
"lint": "prettier --check \"**/*.{json,md}\" && turbo run lint", | ||
"format": "prettier --write \"**/*.{json,md}\" && turbo run format" | ||
|
@@ -13,9 +15,9 @@ | |
"apps/*" | ||
], | ||
"devDependencies": { | ||
"@changesets/cli": "^2.27.8", | ||
"prettier": "^3.1.1", | ||
"turbo": "^2.1.2" | ||
"@changesets/cli": "^2.27.9", | ||
"prettier": "^3.3.3", | ||
"turbo": "^2.1.3" | ||
}, | ||
"packageManager": "[email protected].29" | ||
"packageManager": "[email protected].30" | ||
} |
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,61 @@ | ||
import { expect, test } from 'bun:test'; | ||
import { combineCspHeaders } from '../src/utils/cspHelpers'; | ||
import { | ||
normalizeHeaderValue, | ||
normalizeCspValue, | ||
} from '../src/utils/headerNormalizers'; | ||
|
||
test('combineCspHeaders should return null for both null inputs', () => { | ||
expect(combineCspHeaders(null, null)).toBeNull(); | ||
}); | ||
|
||
test('combineCspHeaders should return newCsp when existingCsp is null', () => { | ||
const newCsp = "default-src 'self'"; | ||
expect(combineCspHeaders(null, newCsp)).toBe(newCsp); | ||
}); | ||
|
||
test('combineCspHeaders should return existingCsp when newCsp is null', () => { | ||
const existingCsp = "default-src 'self'"; | ||
expect(combineCspHeaders(existingCsp, null)).toBe(existingCsp); | ||
}); | ||
|
||
test('combineCspHeaders should combine two CSP headers', () => { | ||
const existingCsp = "default-src 'self'; script-src 'unsafe-inline'"; | ||
const newCsp = "script-src 'self'; img-src 'none'"; | ||
const expectedCsp = | ||
"default-src 'self'; script-src 'unsafe-inline' 'self'; img-src 'none'"; | ||
expect(combineCspHeaders(existingCsp, newCsp)).toBe(expectedCsp); | ||
}); | ||
|
||
test('combineCspHeaders should handle duplicate directives correctly', () => { | ||
const existingCsp = "default-src 'self'; script-src 'unsafe-inline'"; | ||
const newCsp = "script-src 'unsafe-inline' 'self'"; | ||
const expectedCsp = "default-src 'self'; script-src 'unsafe-inline' 'self'"; | ||
expect(combineCspHeaders(existingCsp, newCsp)).toBe(expectedCsp); | ||
}); | ||
|
||
test('normalizeHeaderValue should return null for null input', () => { | ||
expect(normalizeHeaderValue(null)).toBeNull(); | ||
}); | ||
|
||
test('normalizeHeaderValue should trim whitespace from string input', () => { | ||
expect(normalizeHeaderValue(' test ')).toBe('test'); | ||
}); | ||
|
||
test('normalizeHeaderValue should join array of strings with a comma and space', () => { | ||
expect(normalizeHeaderValue(['value1', 'value2'])).toBe('value1, value2'); | ||
}); | ||
|
||
test('normalizeHeaderValue should convert number to string', () => { | ||
expect(normalizeHeaderValue(123)).toBe('123'); | ||
}); | ||
|
||
test('normalizeCspValue should trim whitespace from string input', () => { | ||
expect(normalizeCspValue(' directive ')).toBe('directive'); | ||
}); | ||
|
||
test('normalizeCspValue should join array of strings with a space', () => { | ||
expect(normalizeCspValue(['directive1', 'directive2'])).toBe( | ||
'directive1 directive2', | ||
); | ||
}); |
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