Added vitest (#5)
* Moved eslint and @nuxt/eslint to devDependencies * Added vitest to project and 1 test * Tweaked Sonar workflow in order to run tests and coverage * Removed offending config line
This commit is contained in:
parent
c98879430b
commit
3b58a25ccf
9 changed files with 942 additions and 15 deletions
12
.github/workflows/sonar.yml
vendored
12
.github/workflows/sonar.yml
vendored
|
|
@ -18,6 +18,18 @@ jobs:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
- name: Setup node environment
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: "22"
|
||||||
|
cache: "npm"
|
||||||
|
- name: Install dependencies
|
||||||
|
run: npm ci
|
||||||
|
- name: Run tests and generate coverage
|
||||||
|
run: npm run coverage
|
||||||
|
continue-on-error: true
|
||||||
|
env:
|
||||||
|
CI: true
|
||||||
- name: SonarQube Scan
|
- name: SonarQube Scan
|
||||||
uses: SonarSource/sonarqube-scan-action@v6
|
uses: SonarSource/sonarqube-scan-action@v6
|
||||||
env:
|
env:
|
||||||
|
|
|
||||||
|
|
@ -7,5 +7,6 @@ export default withNuxt(eslintPluginPrettierRecommended, {
|
||||||
rules: {
|
rules: {
|
||||||
"@typescript-eslint/no-explicit-any": "off",
|
"@typescript-eslint/no-explicit-any": "off",
|
||||||
"@typescript-eslint/no-require-imports": "off",
|
"@typescript-eslint/no-require-imports": "off",
|
||||||
|
"@typescript-eslint/no-unused-vars": "warn",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
||||||
846
package-lock.json
generated
846
package-lock.json
generated
File diff suppressed because it is too large
Load diff
16
package.json
16
package.json
|
|
@ -9,19 +9,27 @@
|
||||||
"preview": "nuxt preview",
|
"preview": "nuxt preview",
|
||||||
"postinstall": "nuxt prepare",
|
"postinstall": "nuxt prepare",
|
||||||
"lint": "eslint .",
|
"lint": "eslint .",
|
||||||
"lint-files": "eslint --ext .js,.ts,.vue"
|
"lint-files": "eslint --ext .js,.ts,.vue",
|
||||||
|
"vitest": "vitest",
|
||||||
|
"test": "vitest run",
|
||||||
|
"coverage": "vitest run --coverage"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@nuxt/eslint": "^1.9.0",
|
|
||||||
"eslint": "^9.38.0",
|
|
||||||
"nuxt": "^4.1.3",
|
"nuxt": "^4.1.3",
|
||||||
"vue": "^3.5.22",
|
"vue": "^3.5.22",
|
||||||
"vue-router": "^4.6.3"
|
"vue-router": "^4.6.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@nuxt/eslint": "^1.9.0",
|
||||||
|
"@vitejs/plugin-vue": "^6.0.1",
|
||||||
|
"@vitest/coverage-v8": "^4.0.1",
|
||||||
|
"@vue/test-utils": "^2.4.6",
|
||||||
|
"eslint": "^9.38.0",
|
||||||
"eslint-config-prettier": "^10.1.8",
|
"eslint-config-prettier": "^10.1.8",
|
||||||
"eslint-plugin-prettier": "^5.5.4",
|
"eslint-plugin-prettier": "^5.5.4",
|
||||||
|
"happy-dom": "^20.0.8",
|
||||||
"prettier": "^3.6.2",
|
"prettier": "^3.6.2",
|
||||||
"typescript": "^5.9.3"
|
"typescript": "^5.9.3",
|
||||||
|
"vitest": "^4.0.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,5 +8,5 @@ sonar.sources=app, tests
|
||||||
sonar.inclusions=app/**/*.ts, app/**/*.js, app/**/*.vue, app/**/*.css, app/**/*.scss, tests/**/*.spec.ts
|
sonar.inclusions=app/**/*.ts, app/**/*.js, app/**/*.vue, app/**/*.css, app/**/*.scss, tests/**/*.spec.ts
|
||||||
sonar.exclusions=**/node_modules/**, **/coverage/**, *.config.ts
|
sonar.exclusions=**/node_modules/**, **/coverage/**, *.config.ts
|
||||||
sonar.coverage.exclusions=tests/**, *.config.ts
|
sonar.coverage.exclusions=tests/**, *.config.ts
|
||||||
# sonar.javascript.lcov.reportPaths=coverage/lcov.info
|
sonar.javascript.lcov.reportPaths=coverage/lcov.info
|
||||||
# sonar.testExecutionReportPaths=coverage/sonar-report.xml
|
# sonar.testExecutionReportPaths=coverage/sonar-report.xml
|
||||||
|
|
|
||||||
18
tests/app.test.ts
Normal file
18
tests/app.test.ts
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
import type { VueWrapper } from "@vue/test-utils";
|
||||||
|
import { mount } from "@vue/test-utils";
|
||||||
|
import App from "../app/app.vue";
|
||||||
|
|
||||||
|
describe("app.vue", () => {
|
||||||
|
const wrapper: VueWrapper = mount(App, {
|
||||||
|
global: {
|
||||||
|
stubs: {
|
||||||
|
NuxtRouteAnnouncer: true,
|
||||||
|
NuxtWelcome: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
it("renders without crashing", () => {
|
||||||
|
expect(wrapper.exists()).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
10
tests/setup.ts
Normal file
10
tests/setup.ts
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
import { vi } from "vitest";
|
||||||
|
|
||||||
|
Object.defineProperty(global, "import", {
|
||||||
|
value: {
|
||||||
|
meta: {
|
||||||
|
glob: vi.fn(() => ({})),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
writable: true,
|
||||||
|
});
|
||||||
|
|
@ -14,11 +14,5 @@
|
||||||
{
|
{
|
||||||
"path": "./.nuxt/tsconfig.node.json"
|
"path": "./.nuxt/tsconfig.node.json"
|
||||||
}
|
}
|
||||||
],
|
]
|
||||||
"compilerOptions": {
|
|
||||||
"paths": {
|
|
||||||
"~/*": ["./src/*"],
|
|
||||||
"@/*": ["./src/*"]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
44
vitest.config.ts
Normal file
44
vitest.config.ts
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
import { defineConfig } from "vitest/config";
|
||||||
|
import vue from "@vitejs/plugin-vue";
|
||||||
|
import { resolve } from "path";
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
plugins: [vue()],
|
||||||
|
test: {
|
||||||
|
globals: true,
|
||||||
|
setupFiles: ["./tests/setup.ts"],
|
||||||
|
environment: "happy-dom",
|
||||||
|
include: ["tests/**/*.test.ts"],
|
||||||
|
coverage: {
|
||||||
|
provider: "v8",
|
||||||
|
reporter: ["text", "html", "lcov"],
|
||||||
|
clean: true,
|
||||||
|
cleanOnRerun: true,
|
||||||
|
exclude: [
|
||||||
|
"node_modules/**",
|
||||||
|
"dist/**",
|
||||||
|
"coverage/**",
|
||||||
|
"**/*.test.ts",
|
||||||
|
"tests/mocks/**",
|
||||||
|
|
||||||
|
// Exclude Nuxt generated files
|
||||||
|
".nuxt/**",
|
||||||
|
".output/**",
|
||||||
|
|
||||||
|
// Exclude TypeScript declaration files
|
||||||
|
"**/*.d.ts",
|
||||||
|
|
||||||
|
// Exclude config files
|
||||||
|
"*.config.*",
|
||||||
|
"assets/icons/**",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
name: "GFiesta",
|
||||||
|
},
|
||||||
|
resolve: {
|
||||||
|
alias: {
|
||||||
|
"~": resolve(__dirname, "./app"),
|
||||||
|
"@": resolve(__dirname, "./app"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
Loading…
Add table
Add a link
Reference in a new issue