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

fix: Custom Cypress tests #2080

Merged
merged 22 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
896d994
docs: Fix custom folder for integration tests
lucasfp13 Oct 26, 2023
5f9a05d
fix: Test command
lucasfp13 Oct 26, 2023
4a41642
chore: Change custom tests folder (cypress/e2e)
lucasfp13 Oct 26, 2023
df15e9f
chore: Change custom tests folder (cypress/)
lucasfp13 Oct 26, 2023
cc37739
Revert "chore: Change custom tests folder (cypress/)"
lucasfp13 Oct 27, 2023
09483e5
chore: Set default support file for Cypress 12.x or superior
lucasfp13 Oct 27, 2023
05b5700
fix: Cypress paths
lucasfp13 Oct 27, 2023
288591f
docs: Steps improvements
lucasfp13 Oct 27, 2023
6d01e99
fix: Prevent running test command without `.faststore`
lucasfp13 Oct 27, 2023
ae371de
fix: Remove unnecessary import
lucasfp13 Oct 27, 2023
7d5282f
fix: Error message typo
lucasfp13 Oct 27, 2023
775a85e
fix: Default Cypress support file as `.js` file
lucasfp13 Oct 27, 2023
581fb5b
feat: Creates a detached local server when running test command
lucasfp13 Oct 31, 2023
930a4d8
fix: Ensures default Cypress 12.x support file creation
lucasfp13 Oct 31, 2023
816fa9d
fix: `@faststore/cli` build
lucasfp13 Oct 31, 2023
d3feead
fix: Remove dev detached process
lucasfp13 Oct 31, 2023
591b881
fix: Generate and setup `.faststore`
lucasfp13 Oct 31, 2023
3a40c20
fix: Check custom Cypress folder before copying
lucasfp13 Oct 31, 2023
1638545
docs: Improve Cypress extension docs
lucasfp13 Oct 31, 2023
6903813
fix: Remove export of `copyCypressFiles` function
lucasfp13 Oct 31, 2023
7b8441d
fix: Apply suggestions from code review
lucasfp13 Oct 31, 2023
721022f
fix: Step number 6
lucasfp13 Oct 31, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ Learn how to add custom integration tests in the following steps.

- Refer to [Cypress documentation](https://docs.cypress.io/guides/overview/why-cypress) for more information on this testing tool.

- Ensure that you are using `@faststore/core` and `@faststore/cli` version 2.1.56 or above. If you are using a previous version, take the following steps:
- Ensure you are using `@faststore/core` `2.1.56` version or above and `@faststore/cli` version `2.2.6` or above. If you have versions lower than these requirements, update them as follows:
1. In your storefront project, open the `package.json` file.
2. Navigate to the `@faststore/core` and `@faststore/cli` dependencies and and update their versions to be at least `2.1.56`.
3. Run `yarn install` to apply these changes.

2. Navigate to the `@faststore/core` and update it to at least `2.1.56`.
3. Navigate to the `@faststore/cli` and update it to at least `2.2.6`.
4. Run `yarn dev` to apply these changes.

---

Expand All @@ -51,15 +51,16 @@ Learn how to add custom integration tests in the following steps.
}
```

---

## Step 2: Integrating custom Cypress tests into your FastStore project

Like any other project using Cypress, you'll follow standard practices, including setting up standard Cypress folders and configuration files. This allows you to seamlessly add and execute your custom integration tests within your project. For further details on Cypress configuration, refer to the official [Cypress configuration](https://docs.cypress.io/guides/references/configuration) guide.

1. In the root directory of your storefront project, create a new folder named `cypress`.
2. Add your custom integration tests within the `cypress` folder.
3. Open a pull request with the changes you have made.
4. Within the pull request, navigate to **Checks > Integration Tests** and check the **Details** section.
2. Add your custom integration tests within the `cypress/integration` folder.
3. With the local server running, run `yarn test` to open the Cypress app and to check your tests execution.
4. Open a pull request with the changes you have made.
5. Within the pull request, navigate to **Checks > Integration Tests** and check the **Details** section.

![checks-integration-tests](https://vtexhelp.vtexassets.com/assets/docs/src/custom-test-checks___583ac9b78e43ebdafde93a735a47d61b.png)

lucasfp13 marked this conversation as resolved.
Show resolved Hide resolved
5. Review the results to check the execution status of your custom integration tests.
6. Review the results to check the execution status of your custom integration tests.
6 changes: 3 additions & 3 deletions packages/cli/src/commands/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Command } from '@oclif/core'
import { spawn } from 'child_process'
import chokidar from 'chokidar'

import { getRoot, tmpDir } from '../utils/directory'
import { generate } from '../utils/generate'
import { getRoot, tmpDir } from '../utils/directory'

/**
* Taken from toolbelt
Expand All @@ -29,7 +29,7 @@ const defaultIgnored = [
const testAbortController = new AbortController()

async function storeTest() {
const testProcess = spawn('yarn test', {
const testProcess = spawn('yarn test:e2e', {
shell: true,
cwd: tmpDir,
signal: testAbortController.signal,
Expand Down Expand Up @@ -59,7 +59,7 @@ export default class Test extends Command {
watcher.close()
})

await generate({ test: true })
await generate({ setup: true })

storeTest()

Expand Down
26 changes: 18 additions & 8 deletions packages/cli/src/utils/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import chalk from 'chalk'

interface GenerateOptions {
setup?: boolean
test?: boolean
}

const ignorePaths = ['node_modules', 'cypress.config.ts']
Expand Down Expand Up @@ -89,12 +88,27 @@ async function copyCypressFiles() {
}

const userStoreConfig = await import(userStoreConfigFileDir)
if (userStoreConfig?.experimental?.enableCypressExtension) {
copySync(`${userDir}/cypress`, `${tmpDir}/cypress/integration`, {

// Copy custom Cypress folder and files
if (
existsSync(`${userDir}/cypress`) &&
userStoreConfig?.experimental?.enableCypressExtension
) {
copySync(`${userDir}/cypress`, `${tmpDir}/cypress`, {
overwrite: true,
})

console.log(`${chalk.green('success')} - Cypress test files copied`)
}

// Create default Cypress 12.x (or superior) support file
if (userStoreConfig?.experimental?.cypressVersion > 9) {
copySync(
`${tmpDir}/cypress/support/index.js`,
`${tmpDir}/cypress/support/e2e.js`,
{ overwrite: false }
)
}
} catch (e) {
console.error(e)
}
Expand Down Expand Up @@ -236,14 +250,10 @@ function createNodeModulesSymbolicLink() {
}

export async function generate(options?: GenerateOptions) {
const { setup = false, test = false } = options ?? {}
const { setup = false } = options ?? {}

let setupPromise: Promise<unknown> | null = null

if (test) {
return copyCypressFiles()
}

if (setup) {
setupPromise = Promise.all([
createTmpFolder(),
Expand Down