@nextsparkjs/theme-default 0.1.0-beta.21 → 0.1.0-beta.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/tests/cypress/support/e2e.ts +89 -0
- package/tests/cypress.config.ts +31 -16
package/package.json
CHANGED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cypress E2E Support File for Theme
|
|
3
|
+
*
|
|
4
|
+
* This file is used when running tests in npm mode (outside monorepo).
|
|
5
|
+
* In monorepo mode, the core support file is used instead via cypress.config.ts.
|
|
6
|
+
*
|
|
7
|
+
* For documentation video commands, install cypress-slow-down:
|
|
8
|
+
* pnpm add -D cypress-slow-down
|
|
9
|
+
* Then uncomment the doc-commands import below.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import '@testing-library/cypress/add-commands'
|
|
13
|
+
|
|
14
|
+
// Import @cypress/grep for test filtering by tags
|
|
15
|
+
import registerCypressGrep from '@cypress/grep'
|
|
16
|
+
registerCypressGrep()
|
|
17
|
+
|
|
18
|
+
// Doc commands are optional (require cypress-slow-down)
|
|
19
|
+
// Uncomment if you have cypress-slow-down installed:
|
|
20
|
+
// import './doc-commands'
|
|
21
|
+
|
|
22
|
+
// Global error handling
|
|
23
|
+
Cypress.on('uncaught:exception', (err) => {
|
|
24
|
+
// Ignore React hydration errors
|
|
25
|
+
if (err.message.includes('Hydration')) {
|
|
26
|
+
return false
|
|
27
|
+
}
|
|
28
|
+
// Ignore ResizeObserver errors
|
|
29
|
+
if (err.message.includes('ResizeObserver')) {
|
|
30
|
+
return false
|
|
31
|
+
}
|
|
32
|
+
return true
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
// Global before hook
|
|
36
|
+
beforeEach(() => {
|
|
37
|
+
cy.clearCookies()
|
|
38
|
+
cy.clearLocalStorage()
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
// Type declarations for @cypress/grep and custom commands
|
|
42
|
+
declare global {
|
|
43
|
+
namespace Cypress {
|
|
44
|
+
interface Chainable {
|
|
45
|
+
/**
|
|
46
|
+
* Custom command to make API requests with better error handling
|
|
47
|
+
*/
|
|
48
|
+
apiRequest(options: Partial<Cypress.RequestOptions>): Chainable<Cypress.Response<any>>
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Login command for authenticated tests
|
|
52
|
+
*/
|
|
53
|
+
login(email: string, password: string): Chainable<void>
|
|
54
|
+
}
|
|
55
|
+
interface SuiteConfigOverrides {
|
|
56
|
+
tags?: string | string[]
|
|
57
|
+
}
|
|
58
|
+
interface TestConfigOverrides {
|
|
59
|
+
tags?: string | string[]
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Custom API request command
|
|
65
|
+
Cypress.Commands.add('apiRequest', (options) => {
|
|
66
|
+
const defaultOptions = {
|
|
67
|
+
failOnStatusCode: false,
|
|
68
|
+
timeout: 15000,
|
|
69
|
+
headers: {
|
|
70
|
+
'Content-Type': 'application/json',
|
|
71
|
+
...options.headers
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return cy.request({
|
|
75
|
+
...defaultOptions,
|
|
76
|
+
...options
|
|
77
|
+
})
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
// Login command for authenticated tests
|
|
81
|
+
Cypress.Commands.add('login', (email: string, password: string) => {
|
|
82
|
+
cy.session([email, password], () => {
|
|
83
|
+
cy.visit('/login')
|
|
84
|
+
cy.get('[data-testid="email-input"], input[name="email"]').type(email)
|
|
85
|
+
cy.get('[data-testid="password-input"], input[name="password"]').type(password)
|
|
86
|
+
cy.get('[data-testid="submit-button"], button[type="submit"]').click()
|
|
87
|
+
cy.url().should('include', '/dashboard')
|
|
88
|
+
})
|
|
89
|
+
})
|
package/tests/cypress.config.ts
CHANGED
|
@@ -1,41 +1,55 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Cypress Configuration for Default Theme
|
|
3
3
|
*
|
|
4
|
-
* This config
|
|
4
|
+
* This config works in both monorepo and npm mode.
|
|
5
5
|
* Run with: NEXT_PUBLIC_ACTIVE_THEME=default pnpm cy:open
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import { defineConfig } from 'cypress'
|
|
9
9
|
import path from 'path'
|
|
10
10
|
import fs from 'fs'
|
|
11
|
+
import { fileURLToPath } from 'url'
|
|
12
|
+
|
|
13
|
+
// ESM-compatible __dirname
|
|
14
|
+
const __filename = fileURLToPath(import.meta.url)
|
|
15
|
+
const __dirname = path.dirname(__filename)
|
|
11
16
|
|
|
12
17
|
// Paths relative to this config file
|
|
13
18
|
const themeRoot = path.resolve(__dirname, '..')
|
|
14
19
|
const projectRoot = path.resolve(__dirname, '../../../..')
|
|
15
20
|
const narrationsOutputDir = path.join(__dirname, 'cypress/videos/narrations')
|
|
16
21
|
|
|
22
|
+
// Detect if running in npm mode (no packages/core folder) vs monorepo
|
|
23
|
+
const isNpmMode = !fs.existsSync(path.join(projectRoot, 'packages/core'))
|
|
24
|
+
|
|
17
25
|
// Load environment variables
|
|
18
26
|
import dotenv from 'dotenv'
|
|
19
27
|
dotenv.config({ path: path.join(projectRoot, '.env') })
|
|
20
28
|
|
|
21
|
-
// Server port (from .env or default
|
|
22
|
-
const port = process.env.PORT ||
|
|
29
|
+
// Server port (from .env or default 3000)
|
|
30
|
+
const port = process.env.PORT || 3000
|
|
23
31
|
|
|
24
32
|
export default defineConfig({
|
|
25
33
|
e2e: {
|
|
26
34
|
// Base URL for the application
|
|
27
35
|
baseUrl: `http://localhost:${port}`,
|
|
28
36
|
|
|
29
|
-
// Spec patterns: core tests
|
|
30
|
-
specPattern:
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
// Spec patterns: theme tests (core tests only in monorepo)
|
|
38
|
+
specPattern: isNpmMode
|
|
39
|
+
? [
|
|
40
|
+
// npm mode: only theme tests
|
|
41
|
+
path.join(__dirname, 'cypress/e2e/**/*.cy.{js,ts}'),
|
|
42
|
+
]
|
|
43
|
+
: [
|
|
44
|
+
// Monorepo: core tests + theme tests
|
|
45
|
+
path.join(projectRoot, 'packages/core/tests/cypress/e2e/core/**/*.cy.{js,ts}'),
|
|
46
|
+
path.join(__dirname, 'cypress/e2e/**/*.cy.{js,ts}'),
|
|
47
|
+
],
|
|
48
|
+
|
|
49
|
+
// Support file (theme-local in npm mode, core in monorepo)
|
|
50
|
+
supportFile: isNpmMode
|
|
51
|
+
? path.join(__dirname, 'cypress/support/e2e.ts')
|
|
52
|
+
: path.join(projectRoot, 'packages/core/tests/cypress/support/e2e.ts'),
|
|
39
53
|
|
|
40
54
|
// Fixtures folder (theme-specific)
|
|
41
55
|
fixturesFolder: path.join(__dirname, 'cypress/fixtures'),
|
|
@@ -96,15 +110,16 @@ export default defineConfig({
|
|
|
96
110
|
grepOmitFiltered: true,
|
|
97
111
|
},
|
|
98
112
|
|
|
99
|
-
setupNodeEvents(on, config) {
|
|
113
|
+
async setupNodeEvents(on, config) {
|
|
100
114
|
// Allure plugin setup (allure-cypress)
|
|
101
|
-
const { allureCypress } =
|
|
115
|
+
const { allureCypress } = await import('allure-cypress/reporter')
|
|
102
116
|
allureCypress(on, config, {
|
|
103
117
|
resultsDir: path.join(__dirname, 'cypress/allure-results'),
|
|
104
118
|
})
|
|
105
119
|
|
|
106
120
|
// @cypress/grep plugin for test filtering by tags
|
|
107
|
-
|
|
121
|
+
const grepPlugin = await import('@cypress/grep/src/plugin.js')
|
|
122
|
+
;(grepPlugin.default || grepPlugin)(config)
|
|
108
123
|
|
|
109
124
|
// Documentation video tasks
|
|
110
125
|
on('task', {
|