Skip to content

Commit

Permalink
feat: add yarn modern pnp support (#599)
Browse files Browse the repository at this point in the history
  • Loading branch information
PilotConway authored May 5, 2023
1 parent ad8e313 commit 73fc04a
Show file tree
Hide file tree
Showing 11 changed files with 2,537 additions and 8 deletions.
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 @@ -40,6 +40,7 @@
- Use [pnpm](#pnpm)
- Use [Yarn Classic](#yarn-classic)
- Use [Yarn Modern](#yarn-modern)
- Use [Yarn Plug'n'Play](#yarn-plugnplay)
- Use [Yarn workspaces](#yarn-workspaces)
- Use [custom cache key](#custom-cache-key)
- Run tests on multiple [Node versions](#node-versions)
Expand Down Expand Up @@ -1077,6 +1078,31 @@ See [example-yarn-modern.yml](.github/workflows/example-yarn-modern.yml) for an

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

### Yarn Plug'n'Play

When using [Yarn Modern](https://yarnpkg.com/) (Yarn 2 and later) with [Plug'n'Play](https://yarnpkg.com/features/pnp) enabled, you will need to use the `command` parameter to run [yarn dlx](https://yarnpkg.com/cli/dlx) instead of [npx](https://docs.npmjs.com/cli/v9/commands/npx).

```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)

### Yarn workspaces

This action should discover the Yarn workspaces correctly. For example, see folder [examples/start-and-yarn-workspaces](examples/start-and-yarn-workspaces) and workflow file [example-start-and-yarn-workspaces.yml](.github/workflows/example-start-and-yarn-workspaces.yml)
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

0 comments on commit 73fc04a

Please sign in to comment.