forked from Klaveness-Digital/cypress-cucumber-preprocessor
-
-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for CT using Vite as bundler
This currently relies on a small patch of @cypress/vite-dev-server [1]. Hopefully this patch can be submitted and accepted upstream. This fixes #698 [2]. [2] https://github.com/cypress-io/cypress/tree/develop/npm/vite-dev-server [1] #698
- Loading branch information
Showing
16 changed files
with
151 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { defineConfig } from "cypress"; | ||
import { devServer } from "@cypress/vite-dev-server"; | ||
import react from "@vitejs/plugin-react"; | ||
import { viteCommonjs } from "@originjs/vite-plugin-commonjs"; | ||
import { addCucumberPreprocessorPlugin } from "@badeball/cypress-cucumber-preprocessor"; | ||
import { createRollupPlugin } from "@badeball/cypress-cucumber-preprocessor/rollup"; | ||
|
||
export default defineConfig({ | ||
component: { | ||
specPattern: "**/*.feature", | ||
devServer(devServerConfig) { | ||
return devServer({ | ||
...devServerConfig, | ||
framework: "react", | ||
viteConfig: { | ||
plugins: [ | ||
react(), | ||
createRollupPlugin(devServerConfig.cypressConfig), | ||
viteCommonjs(), | ||
], | ||
}, | ||
}); | ||
}, | ||
async setupNodeEvents(on, config) { | ||
// This is required for the preprocessor to be able to generate JSON reports after each run, and more. | ||
await addCucumberPreprocessorPlugin(on, config); | ||
|
||
// Make sure to return the config object as it might have been modified by the plugin. | ||
return config; | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Feature: App | ||
Scenario: render | ||
Given I render the component | ||
Then I should see the text "Hello world!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import * as preprocessor from "@badeball/cypress-cucumber-preprocessor"; | ||
|
||
import { mount } from "cypress/react18" | ||
|
||
import App from "../../src/App"; | ||
|
||
const { Given, Then } = preprocessor | ||
|
||
Given("I render the component", () => { | ||
mount(<App />); | ||
}); | ||
|
||
Then("I should see the text {string}", (text: string) => { | ||
cy.contains(text).should("exist"); | ||
}); |
14 changes: 14 additions & 0 deletions
14
examples/ct-vite-react-ts/cypress/support/component-index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width,initial-scale=1.0"> | ||
<title>Components App</title> | ||
|
||
</head> | ||
<body> | ||
|
||
<div data-cy-root></div> | ||
</body> | ||
</html> |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"scripts": { | ||
"postinstall": "patch-package" | ||
}, | ||
"dependencies": { | ||
"@badeball/cypress-cucumber-preprocessor": "latest", | ||
"@cypress/vite-dev-server": "latest", | ||
"@originjs/vite-plugin-commonjs": "latest", | ||
"@vitejs/plugin-react": "latest", | ||
"cypress": "latest", | ||
"patch-package": "latest", | ||
"react": "latest", | ||
"react-dom": "latest", | ||
"typescript": "latest" | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
examples/ct-vite-react-ts/patches/@cypress+vite-dev-server+5.0.5.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
diff --git a/node_modules/@cypress/vite-dev-server/client/initCypressTests.js b/node_modules/@cypress/vite-dev-server/client/initCypressTests.js | ||
index f0602c1..d7f05a0 100644 | ||
--- a/node_modules/@cypress/vite-dev-server/client/initCypressTests.js | ||
+++ b/node_modules/@cypress/vite-dev-server/client/initCypressTests.js | ||
@@ -36,7 +36,7 @@ if (supportFile) { | ||
// So we use the "@fs" bit to load the test file using its absolute path | ||
// Normalize path to not include a leading slash (different on Win32 vs Unix) | ||
const normalizedAbsolutePath = CypressInstance.spec.absolute.replace(/^\//, '') | ||
-const testFileAbsolutePathRoute = `${devServerPublicPathRoute}/@fs/${normalizedAbsolutePath}` | ||
+const testFileAbsolutePathRoute = `${devServerPublicPathRoute}/@fs/${normalizedAbsolutePath}?import` | ||
|
||
/* Spec file import logic */ | ||
// We need a slash before /src/my-spec.js, this does not happen by default. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function App () { | ||
return <p>Hello world!</p> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"compilerOptions": { | ||
"esModuleInterop": true, | ||
"moduleResolution": "node16", | ||
"jsx": "react-jsx" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Plugin } from "rollup"; | ||
|
||
import { ICypressConfiguration } from "@badeball/cypress-configuration"; | ||
|
||
import { compile } from "../template"; | ||
|
||
export function createRollupPlugin(config: ICypressConfiguration): Plugin { | ||
return { | ||
name: "transform-feature", | ||
async transform(src: string, id: string) { | ||
if (/\.feature$/.test(id)) { | ||
return { | ||
code: await compile(config, src, id), | ||
map: null, | ||
}; | ||
} | ||
}, | ||
}; | ||
} | ||
|
||
export default createRollupPlugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Registry, assignRegistry, freeRegistry } from "../registry"; | ||
|
||
const registry = new Registry(false); | ||
|
||
assignRegistry(registry); | ||
|
||
export function getAndFreeRegistry() { | ||
freeRegistry(); | ||
return registry; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters