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

feat: add yarn modern pnp support #599

Merged
merged 14 commits into from
May 5, 2023
Merged
Show file tree
Hide file tree
Changes from 12 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
25 changes: 25 additions & 0 deletions .github/workflows/example-yarn-modern-pnp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: example-yarn-modern-pnp
on:
push:
branches:
- 'master'
pull_request:
workflow_dispatch:

jobs:

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Cypress v10 and higher ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #

yarn-modern-pnp:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Custom Yarn command
uses: ./
with:
working-directory: examples/yarn-modern-pnp
# https://yarnpkg.com/cli/install
install-command: yarn install
command: yarn dlx cypress run
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
- Use [Yarn Classic](#yarn-classic)
- Use [Yarn Modern](#yarn-modern)
- Use [Yarn workspaces](#yarn-workspaces)
- Use [Yarn Plug'n'Play](#yarn-plugnplay)
mschile marked this conversation as resolved.
Show resolved Hide resolved
- Use [custom cache key](#custom-cache-key)
- Run tests on multiple [Node versions](#node-versions)
- Split [install and tests](#split-install-and-tests) into separate jobs
Expand Down Expand Up @@ -1102,6 +1103,31 @@ jobs:

[![Yarn workspaces example](https://github.com/cypress-io/github-action/workflows/example-start-and-yarn-workspaces/badge.svg?branch=master)](.github/workflows/example-start-and-yarn-workspaces.yml)

### Yarn Plug'n'Play

If you are using a modern yarn (Yarn 2 and later) with [Plug'n'Play enabled](https://yarnpkg.com/features/pnp), you will need to use the `command` parameter to run cypress using yarn dlx instead of npx so the imports are correctly resolved and the action can find the correct cypress command.
PilotConway marked this conversation as resolved.
Show resolved Hide resolved

```yaml
name: example-yarn-modern-pnp
on: push
jobs:
yarn-classic:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Cypress run
uses: cypress-io/github-action@v5
with:
working-directory: examples/yarn-modern-pnp
install-command: yarn install
command: yarn dlx cypress run
```

[![Yarn Plug'n'Play example](https://github.com/cypress-io/github-action/actions/workflows/example-yarn-modern-pnp.yml/badge.svg?branch=master)](https://github.com/cypress-io/github-action/actions/workflows/example-yarn-modern-pnp.yml)

**Caution**: using the action parameter `command` causes multiple other parameters to be ignored. [See `command` section for more information.](#custom-test-command)

### Custom cache key

Sometimes the default cache key does not work. For example, if you cannot share the Node modules across Node versions due to native extensions. In that case pass your own `cache-key` parameter.
Expand Down
9 changes: 5 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75008,10 +75008,6 @@ const runTests = async () => {
quiet: getInputBool('quiet'),
component: getInputBool('component')
}
const cypressModulePath =
require.resolve('cypress', { paths: [workingDirectory] }) ||
'cypress'
const cypress = require(cypressModulePath)
const runTests = getInputBool('runTests', true)
const spec = getSpecsList()

Expand All @@ -75033,6 +75029,11 @@ const runTests = async () => {
return runTestsUsingCommandLine()
}

const cypressModulePath =
require.resolve('cypress', { paths: [workingDirectory] }) ||
'cypress'
const cypress = require(cypressModulePath)

debug('Running Cypress tests using NPM module API')
debug(`requiring cypress dependency, cwd is ${process.cwd()}`)
debug(`working directory ${workingDirectory}`)
Expand Down
873 changes: 873 additions & 0 deletions examples/yarn-modern-pnp/.yarn/releases/yarn-3.5.0.cjs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions examples/yarn-modern-pnp/.yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
yarnPath: .yarn/releases/yarn-3.5.0.cjs
3 changes: 3 additions & 0 deletions examples/yarn-modern-pnp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# example: yarn-modern-pnp

This example demonstrates installing dependencies using [Yarn Modern (version 2 and later)](https://yarnpkg.com/) with [Plug'n'Play](https://yarnpkg.com/features/pnp) turned on.
10 changes: 10 additions & 0 deletions examples/yarn-modern-pnp/cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const { defineConfig } = require('cypress')

module.exports = defineConfig({
fixturesFolder: false,
e2e: {
setupNodeEvents(on, config) {},
supportFile: false,
baseUrl: 'https://example.cypress.io/',
},
})
7 changes: 7 additions & 0 deletions examples/yarn-modern-pnp/cypress/e2e/spec.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/// <reference types="cypress" />
describe('example: yarn-modern', () => {
it('loads the deployed site', () => {
cy.visit('/')
cy.contains('h1', 'Kitchen Sink')
})
})
13 changes: 13 additions & 0 deletions examples/yarn-modern-pnp/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "example-yarn-modern",
"version": "1.0.0",
"description": "Use modern yarn with pnp",
"scripts": {
"test": "cypress run"
},
"private": true,
"devDependencies": {
"cypress": "12.11.0"
},
"packageManager": "[email protected]"
}
Loading