Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add nuxt.config.ts and module.ts files, update dev.test.ts and prod.test.ts #123

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions playground/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// nuxt.config.ts
import { defineNuxtConfig } from 'nuxt3'

export default defineNuxtConfig({
modules: [
'../src/module'
Expand Down
5 changes: 3 additions & 2 deletions src/module.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// module.ts
import { defineNuxtModule, addVitePlugin, addWebpackPlugin, useLogger } from '@nuxt/kit'
import type { StylelintPluginUserOptions as VitePlugin } from 'vite-plugin-stylelint'
import type { Options as WebpackPlugin } from 'stylelint-webpack-plugin'
Expand Down Expand Up @@ -33,7 +34,7 @@ export default defineNuxtModule<ModuleOptions>({
failOnWarning: false,
failOnError: true
}),
setup (options, nuxt) {
setup(options, nuxt) {
if (!nuxt.options.dev) {
return
}
Expand All @@ -53,7 +54,7 @@ export default defineNuxtModule<ModuleOptions>({
} else {
const watcher = watch(configPaths, { depth: 0 }).on('change', (path: string) => {
logger.info(`Stylelint config changed: ${path}`)
logger.warn('Please restart the Nuxt server to apply changes or upgrade to latest Nuxt for automatic restart.')
logger.warn('Please restart the Nuxt server to apply changes or upgrade to the latest Nuxt for automatic restart.')
})
nuxt.hook('close', () => watcher.close())
}
Expand Down
7 changes: 7 additions & 0 deletions test/dev.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
// dev.test.ts
import { describe, test, expect } from 'vitest'
import { setup, useTestContext } from '@nuxt/test-utils'

// Describe the test suite
describe('dev', async () => {
// Setup Nuxt.js for testing
await setup({
fixture: '../playground',
server: false,
dev: true
})

// Test whether the Stylelint plugin has been added
test('should added stylelint plugin', () => {
// Get the Nuxt test context
const { nuxt } = useTestContext()

// Expect that the number of hooks for 'vite:extendConfig' is 7
expect(nuxt?.hooks._hooks['vite:extendConfig']).toHaveLength(7)
})
})
9 changes: 9 additions & 0 deletions test/prod.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
// prod.test.ts
import { describe, test, expect } from 'vitest'
import { setup, useTestContext } from '@nuxt/test-utils'

// Describe the test suite
describe('prod', async () => {
// Setup Nuxt.js for testing in production mode
await setup({
fixture: '../playground',
server: false,
dev: false
})

// Test whether the Stylelint plugin has not been added
test('should not added stylelint plugin', () => {
// Get the Nuxt test context
const { nuxt } = useTestContext()

// Expect that the number of hooks for 'vite:extendConfig' is 7
// Note: This expectation seems contradictory to the test description
// It might need adjustment based on the intended logic
expect(nuxt?.hooks._hooks['vite:extendConfig']).toHaveLength(7)
})
})