Skip to content

Commit 99c94de

Browse files
Apps/nutritionfacts/additionalTests (#146)
* specify environment * add html tests * use config environment * [email protected] * Update apps/nutritionfacts/index.test.ts Co-authored-by: Copilot <[email protected]> * Update apps/nutritionfacts/index.test.ts Co-authored-by: Copilot <[email protected]> * remove comment --------- Co-authored-by: Copilot <[email protected]>
1 parent a6fa89e commit 99c94de

File tree

6 files changed

+66
-5
lines changed

6 files changed

+66
-5
lines changed

apps/nutritionfacts/index.test.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// @ts-expect-error Vite raw import
2+
import html from "./index.html?raw"
3+
import { describe, it, expect, beforeEach } from "vitest"
4+
5+
describe('index.html', () => {
6+
beforeEach(() => {
7+
document.documentElement.innerHTML = html
8+
document.documentElement.setAttribute('lang', 'en')
9+
})
10+
11+
it('should have correct doctype', () => {
12+
// jsdom does not expose doctype, so we skip this in jsdom
13+
expect(document.documentElement.lang).toBe('en')
14+
})
15+
16+
it('should have correct meta tags', () => {
17+
const charset = document.querySelector('meta[charset]')
18+
expect(charset).not.toBeNull()
19+
expect(charset?.getAttribute('charset')).toBe('UTF-8')
20+
21+
const viewport = document.querySelector('meta[name="viewport"]')
22+
expect(viewport).not.toBeNull()
23+
expect(viewport?.getAttribute('content')).toBe('width=device-width, initial-scale=1.0')
24+
25+
const version = document.querySelector('meta[name="application-version"]')
26+
expect(version).not.toBeNull()
27+
expect(version?.getAttribute('content')).toBe('%VITE_PACKAGE_VERSION%')
28+
29+
const name = document.querySelector('meta[name="application-name"]')
30+
expect(name).not.toBeNull()
31+
expect(name?.getAttribute('content')).toBe('%VITE_PACKAGE_NAME%')
32+
})
33+
34+
it('should have favicon link', () => {
35+
const favicon = document.querySelector('link[rel="icon"]')
36+
expect(favicon).not.toBeNull()
37+
expect(favicon?.getAttribute('type')).toBe('image/svg+xml')
38+
expect(favicon?.getAttribute('href')).toBe('/IgniteAI.svg')
39+
})
40+
41+
it('should have correct title', () => {
42+
expect(document.title).toBe('IgniteAI Nutrition Facts')
43+
})
44+
45+
it('should have root div', () => {
46+
const root = document.getElementById('root')
47+
expect(root).not.toBeNull()
48+
})
49+
50+
it('should load main script as module', () => {
51+
const script = document.querySelector('script[type="module"]')
52+
expect(script).not.toBeNull()
53+
expect(script?.getAttribute('src')).toBe('/src/Main.tsx')
54+
})
55+
})

apps/nutritionfacts/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@
2828
"update-cache": "vite-node ./scripts/updateCache.mts"
2929
},
3030
"type": "module",
31-
"version": "1.5.2"
31+
"version": "1.5.3"
3232
}

apps/nutritionfacts/src/Main.test.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
/**
2-
* @vitest-environment jsdom
3-
*/
4-
51
import * as React from "react";
62
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
73

apps/nutritionfacts/tests/package.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* @vitest-environment node
3+
*/
4+
15
import { describe, expect, it } from "vitest";
26
import { name as workspaceName } from "../../../package.json" with {
37
type: "json",

apps/nutritionfacts/tests/readme.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* @vitest-environment node
3+
*/
4+
15
import { readFile } from "node:fs/promises";
26
import { describe, expect, it } from "vitest";
37
import { name } from "../package.json" with { type: "json" };

apps/nutritionfacts/vitest.config.mts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const __cdir = path.resolve(__dir, "coverage");
99
export default mergeConfig(baseConfig, {
1010
root: __dirname,
1111
test: {
12+
environment: "jsdom",
13+
include: ["index.test.{ts,tsx}"],
1214
coverage: {
1315
reportsDirectory: __cdir,
1416
},

0 commit comments

Comments
 (0)