Skip to content

Commit

Permalink
test: add module tests (#61)
Browse files Browse the repository at this point in the history
* test: πŸ’ write initial basic and disabled tests with vitest

* test: πŸ’ correctly test that we can disable svgo

* docs: ✏️ update example for disabling svgo

* test: πŸ’ add tests for svgoOptions overrides

* test: πŸ’ update test name

* ci: 🎑 add tests to ci

* test: πŸ’ import module directly instead of using string
  • Loading branch information
cpsoinos authored Nov 5, 2022
1 parent b677235 commit 4bae54e
Show file tree
Hide file tree
Showing 13 changed files with 437 additions and 59 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,42 @@ jobs:

- name: Prettier
run: pnpm run ci:format

vitest:
name: Test
timeout-minutes: 15
runs-on: ubuntu-latest
steps:
- name: Checkout code repository
uses: actions/checkout@v3

- name: Setup node.js
uses: actions/setup-node@v3
with:
node-version: 16

- name: Install pnpm
uses: pnpm/action-setup@v2.2.2
id: pnpm-install
with:
version: 7.9.5
run_install: false

- name: Get pnpm store directory
id: pnpm-cache
run: |
echo "::set-output name=pnpm_cache_dir::$(pnpm store path)"
- name: Setup pnpm cache
uses: actions/cache@v3
with:
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install

- name: Vitest
run: pnpm run test
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
dist
**/node_modules
playground/.nuxt
**/.nuxt
**/*.d.ts
**/pnpm-lock.yaml
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ import { defineNuxtConfig } from 'nuxt'

export default defineNuxtConfig({
modules: ['nuxt-svgo'],
svgoOptions: {
svgo: {
svgo: false
}
})
Expand Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,vue,md,mdx,gql,graphql,json,yml,yaml}\"",
"lint": "eslint --ext .js,.ts, --fix .",
"prepack": "nuxt-module-build",
"prepare": "husky install"
"prepare": "husky install",
"test": "NUXT_TELEMETRY_DISABLED=1 pnpm nuxi prepare test/fixtures/basic && JITI_ESM_RESOLVE=1 vitest run --dir test",
"test:dev": "NUXT_TELEMETRY_DISABLED=1 NUXT_TEST_DEV=true pnpm test:fixtures"
},
"dependencies": {
"@nuxt/kit": "npm:@nuxt/kit-edge@latest",
Expand All @@ -59,6 +61,7 @@
"@cpsoinos/eslint-config-typescript": "0.2.2",
"@cpsoinos/prettier-config": "0.0.0",
"@nuxt/module-builder": "latest",
"@nuxt/test-utils": "3.0.0-rc.13",
"@nuxtjs/eslint-config-typescript": "latest",
"@types/svgo": "2.6.4",
"commitizen": "4.2.5",
Expand All @@ -67,7 +70,8 @@
"husky": "8.0.1",
"nuxt": "3.0.0-rc.13",
"pnpm": "7.9.5",
"prettier": "2.7.1"
"prettier": "2.7.1",
"vitest": "^0.24.5"
},
"commitlint": {
"extends": [
Expand Down
6 changes: 6 additions & 0 deletions playground/custom.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// custom.d.ts
declare module '*.svg' {
import type { DefineComponent } from 'vue'
const component: DefineComponent
export default component
}
Loading

0 comments on commit 4bae54e

Please sign in to comment.