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 support for pnpm (install and cache deps) #586

Merged
merged 3 commits into from Jul 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
210 changes: 210 additions & 0 deletions .github/workflows/example-basic-pnpm.yml
@@ -0,0 +1,210 @@
name: example-basic
on:
push:
branches:
- 'master'
pull_request:
jobs:
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Cypress v9 and lower ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #

basic-pnpm-ubuntu-18:
runs-on: ubuntu-18.04
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: latest

- name: Cypress tests
# normally you would write
# uses: cypress-io/github-action@v2
uses: ./
# the parameters below are only necessary
# because we are running these examples in a monorepo
with:
working-directory: examples/v9/basic-pnpm
# just for full picture after installing Cypress
# print information about detected browsers, etc
# see https://on.cypress.io/command-line#cypress-info
build: npx cypress info

basic-pnpm-ubuntu-20:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: latest

- name: Cypress tests
uses: ./
with:
working-directory: examples/v9/basic-pnpm
build: npx cypress info

basic-pnpm-on-windows:
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: latest

- name: Cypress tests
uses: ./
with:
working-directory: examples/v9/basic-pnpm
build: npx cypress info

basic-pnpm-on-mac:
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: latest

- name: Cypress tests
uses: ./
with:
working-directory: examples/v9/basic-pnpm
build: npx cypress info

# skips the binary installation
# shows that the job should not fail
# https://github.com/cypress-io/github-action/issues/327
basic-pnpm-without-binary-install:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: latest

- name: Cypress tests
uses: ./
with:
working-directory: examples/v9/basic-pnpm
# since we do not install Cypress
# we should not attempt to run tests
runTests: false
env:
# skip the binary install
CYPRESS_INSTALL_BINARY: 0

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

basic-pnpm-ubuntu-18-v10:
runs-on: ubuntu-18.04
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: latest

- name: Cypress tests
# normally you would write
# uses: cypress-io/github-action@v2
uses: ./
# the parameters below are only necessary
# because we are running these examples in a monorepo
with:
working-directory: examples/v10/basic-pnpm
# just for full picture after installing Cypress
# print information about detected browsers, etc
# see https://on.cypress.io/command-line#cypress-info
build: npx cypress info

basic-pnpm-ubuntu-20-v10:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: latest

- name: Cypress tests
uses: ./
with:
working-directory: examples/v10/basic-pnpm
build: npx cypress info

basic-pnpm-on-windows-v10:
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: latest

- name: Cypress tests
uses: ./
with:
working-directory: examples/v10/basic-pnpm
build: npx cypress info

basic-pnpm-on-mac-v10:
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: latest

- name: Cypress tests
uses: ./
with:
working-directory: examples/v10/basic-pnpm
build: npx cypress info

# skips the binary installation
# shows that the job should not fail
# https://github.com/cypress-io/github-action/issues/327
basic-pnpm-without-binary-install-v10:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: latest

- name: Cypress tests
uses: ./
with:
working-directory: examples/v10/basic-pnpm
# since we do not install Cypress
# we should not attempt to run tests
runTests: false
env:
# skip the binary install
CYPRESS_INSTALL_BINARY: 0
24 changes: 22 additions & 2 deletions dist/index.js
Expand Up @@ -74706,15 +74706,22 @@ const yarnFilename = path.join(
findYarnWorkspaceRoot(workingDirectory) || workingDirectory,
'yarn.lock'
)
const pnpmLockFilename = path.join(workingDirectory, 'pnpm-lock.yaml')
const packageLockFilename = path.join(
workingDirectory,
'package-lock.json'
)

const useYarn = () => fs.existsSync(yarnFilename)

const usePnpm = () => fs.existsSync(pnpmLockFilename)

const lockHash = () => {
const lockFilename = useYarn() ? yarnFilename : packageLockFilename
const lockFilename = useYarn()
? yarnFilename
: usePnpm()
? pnpmLockFilename
: packageLockFilename
const fileHash = hasha.fromFileSync(lockFilename)
debug(`Hash from file ${lockFilename} is ${fileHash}`)
return fileHash
Expand All @@ -74729,6 +74736,8 @@ const getNpmCache = () => {
if (!key) {
if (useYarn()) {
key = `yarn-${platformAndArch}-${hash}`
} else if (usePnpm()) {
key = `pnpm-${platformAndArch}-${hash}`
} else {
key = `npm-${platformAndArch}-${hash}`
}
Expand All @@ -74738,6 +74747,8 @@ const getNpmCache = () => {

if (useYarn()) {
o.inputPath = path.join(homeDirectory, '.cache', 'yarn')
} else if (usePnpm()) {
o.inputPath = NPM_CACHE_FOLDER
} else {
o.inputPath = NPM_CACHE_FOLDER
}
Expand Down Expand Up @@ -74842,9 +74853,18 @@ const install = () => {
cypressCommandOptions
)
})
} else if (usePnpm()) {
debug('installing NPM dependencies using pnpm')
return io.which('pnpm', true).then((pnpmPath) => {
debug(`pnpm at "${pnpmPath}"`)
return exec.exec(
quote(pnpmPath),
['install', '--frozen-lockfile'],
cypressCommandOptions
)
})
} else {
debug('installing NPM dependencies')

return io.which('npm', true).then((npmPath) => {
debug(`npm at "${npmPath}"`)
return exec.exec(quote(npmPath), ['ci'], cypressCommandOptions)
Expand Down
9 changes: 9 additions & 0 deletions examples/v10/basic-pnpm/cypress.config.js
@@ -0,0 +1,9 @@
const { defineConfig } = require('cypress')

module.exports = defineConfig({
fixturesFolder: false,
e2e: {
setupNodeEvents(on, config) {},
supportFile: false,
},
})
6 changes: 6 additions & 0 deletions examples/v10/basic-pnpm/cypress/e2e/spec.cy.js
@@ -0,0 +1,6 @@
it('works', () => {
expect(42).to.equal(21 + 21)
cy.visit('https://example.cypress.io').then(() => {
expect('hello').to.equal('hello')
})
})
15 changes: 15 additions & 0 deletions examples/v10/basic-pnpm/package.json
@@ -0,0 +1,15 @@
{
"name": "example-basic",
"version": "1.0.0",
"description": "basic example how to run Cypress tests",
"main": "index.js",
"scripts": {
"test": "cypress run"
},
"author": "",
"license": "ISC",
"private": true,
"devDependencies": {
"cypress": "^10.0.0"
}
}