I am trying to create cypress plugin locally in a forked build-example-basic repo (so I can run it on Netlify under https://app.netlify.com/sites/condescending-knuth-7cff53)
my root package has plugin as a dev dependency
{
"name": "example-basic",
"private": true,
"version": "0.0.0",
"description": "Example Netlify Build Site",
"scripts": {
"docs": "md-magic --path '**/*.md' --ignore 'node_modules'",
"build": "mkdir -p build && cp src/index.html build",
"postinstall": "echo nothing to do post NPM install"
},
"author": "David Wells",
"license": "MIT",
"devDependencies": {
"markdown-magic": "^1.0.0",
"netlify-plugin-cypress": "file:plugins/cypress"
},
"dependencies": {
"@netlify/sitemap-plugin": "0.0.2"
}
}
The plugin in plugins/cypress has its own package.json
{
"name": "netlify-plugin-cypress",
"private": true,
"version": "0.0.1",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"cypress": "3.4.1"
}
}
On the first deploy, plugin's dependencies ARE installed, for example in https://app.netlify.com/sites/condescending-knuth-7cff53/deploys/5da086c8bc913d00086e6fa9
9:42:42 AM: Installing dependencies
9:42:42 AM: Started restoring cached node version
9:42:45 AM: Finished restoring cached node version
9:42:46 AM: v10.16.3 is already installed.
9:42:47 AM: Now using node v10.16.3 (npm v6.9.0)
9:42:47 AM: Attempting ruby version 2.6.2, read from environment
9:42:48 AM: Using ruby version 2.6.2
9:42:49 AM: Using PHP version 5.6
9:42:49 AM: Started restoring cached node modules
9:42:49 AM: Finished restoring cached node modules
9:42:49 AM: Installing NPM modules using NPM version 6.9.0
9:42:54 AM: > cypress@3.4.1 postinstall /opt/build/repo/node_modules/netlify-plugin-cypress/node_modules/cypress
9:42:54 AM: > node index.js --exec install
9:42:55 AM: Installing Cypress (version: 3.4.1)
9:42:55 AM:
9:42:55 AM: [13:42:55] Downloading Cypress [started]
9:42:57 AM: [13:42:57] Downloading Cypress [completed]
9:42:57 AM: [13:42:57] Unzipping Cypress [started]
9:43:46 AM: [13:43:46] Unzipping Cypress [completed]
9:43:46 AM: [13:43:46] Finishing Installation [started]
9:43:46 AM: [13:43:46] Finishing Installation [completed]
9:43:46 AM:
9:43:47 AM: You can now open Cypress by running: node_modules/.bin/cypress open
9:43:47 AM: https://on.cypress.io/installing-cypress
9:43:47 AM:
9:43:47 AM: > example-basic@0.0.0 postinstall /opt/build/repo
9:43:47 AM: > echo nothing to do post NPM install
9:43:47 AM: nothing to do post NPM install
9:43:47 AM: added 188 packages from 125 contributors and audited 541 packages in 57.744s
9:43:47 AM: found 0 vulnerabilities
9:43:47 AM: NPM modules installed
There package.json and package-lock.json files in both root and plugin's folders.
When running the plugin requires cypress npm module like this
const cypress = require('cypress')
module.exports = function cypressPlugin (config) {
console.log('cypressPlugin config', config)
postDeploy ....
}
The plugin works just fine, testing deployed site
9:44:11 AM: ❯ Loading plugins
9:44:11 AM: Loading plugin "@netlify/functions" from /opt/buildhome/.nvm/versions/node/v10.16.3/lib/node_modules/@netlify/build/src/plugins/functions/index.js
9:44:11 AM: Loading plugin "cypressPlugin" from netlify-plugin-cypress
9:44:11 AM: cypressPlugin config { baseUrl: 'http://localhost:8080' }
9:44:11 AM: ❯ Running Netlify Build Lifecycle
9:44:11 AM: Found 2 steps. Lets do this!
9:44:11 AM: ┌───────────────────────────────────────────────────────────────┐
9:44:11 AM: │ 1. Running buildFunctions lifecycle from @netlify/functions │
9:44:11 AM: └───────────────────────────────────────────────────────────────┘
9:44:11 AM: No functions directory set. Skipping functions build step
9:44:11 AM: ✔ @netlify/functions.buildFunctions completed in 2ms
9:44:11 AM: ┌──────────────────────────────────────────────────────┐
9:44:11 AM: │ 2. Running postDeploy lifecycle from cypressPlugin │
9:44:11 AM: └──────────────────────────────────────────────────────┘
9:44:11 AM: cypressPlugin start against https://condescending-knuth-7cff53.netlify.com/
...
On the second deploy though, NPM dependencies are not found, here is the build log
9:53:51 AM: Now using node v10.16.3 (npm v6.9.0)
9:53:51 AM: Attempting ruby version 2.6.2, read from environment
9:53:52 AM: Using ruby version 2.6.2
9:53:53 AM: Using PHP version 5.6
9:53:53 AM: Started restoring cached node modules
9:53:53 AM: Finished restoring cached node modules
9:53:53 AM: Started restoring cached go cache
9:53:53 AM: Finished restoring cached go cache
9:53:53 AM: unset GOOS;
9:53:53 AM: unset GOARCH;
9:53:53 AM: export GOROOT='/opt/buildhome/.gimme/versions/go1.12.linux.amd64';
9:53:53 AM: export PATH="/opt/buildhome/.gimme/versions/go1.12.linux.amd64/bin:${PATH}";
9:53:53 AM: go version >&2;
9:53:53 AM: export GIMME_ENV='/opt/buildhome/.gimme/env/go1.12.linux.amd64.env';
9:53:53 AM: go version go1.12 linux/amd64
9:53:53 AM: Installing missing commands
9:53:53 AM: Verify run directory
9:53:55 AM: Found Netlify Build that didn't match the version latest. Installing now.
9:54:05 AM: npm
9:54:05 AM: WARN deprecated flatten@1.0.2: I wrote this module a very long time ago; you should use something else.
9:54:17 AM: /opt/buildhome/.nvm/versions/node/v10.16.3/bin/netlify-build -> /opt/buildhome/.nvm/versions/node/v10.16.3/lib/node_modules/@netlify/build/src/core/bin.js
9:54:17 AM: + @netlify/build@0.0.21
9:54:17 AM: updated 3 packages in 21.739s
9:54:17 AM: Executing netlify-build command (lifecycle trial enabled): netlify-build
9:54:18 AM: ❯ Starting Netlify Build
9:54:18 AM: https://github.com/netlify/build
9:54:18 AM: ❯ Using config file:
9:54:18 AM: /opt/build/repo/netlify.yml
9:54:18 AM: ❯ Loading plugins
9:54:18 AM: Loading plugin "@netlify/functions" from /opt/buildhome/.nvm/versions/node/v10.16.3/lib/node_modules/@netlify/build/src/plugins/functions/index.js
9:54:18 AM: Loading plugin "cypressPlugin" from netlify-plugin-cypress
9:54:18 AM: ┌─────────────────────────────┐
9:54:18 AM: │ Netlify Build Error! │
9:54:18 AM: └─────────────────────────────┘
9:54:18 AM: Error importing 'cypressPlugin' plugin:
9:54:18 AM: Cannot find module 'cypress'
9:54:18 AM: ┌─────────────────────────────┐
9:54:18 AM: │ Error Stack Trace │
9:54:18 AM: └─────────────────────────────┘
9:54:18 AM: Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
9:54:18 AM: Function.Module._load (internal/modules/cjs/loader.js:562:25)
9:54:18 AM: Module.require (internal/modules/cjs/loader.js:692:17)
9:54:18 AM: require (internal/modules/cjs/helpers.js:25:18)
9:54:18 AM: Object.<anonymous> (plugins/cypress/index.js:4:17)
9:54:18 AM: Module._compile (internal/modules/cjs/loader.js:778:30)
9:54:18 AM: Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
9:54:18 AM: Module.load (internal/modules/cjs/loader.js:653:32)
9:54:18 AM: tryModuleLoad (internal/modules/cjs/loader.js:593:12)
9:54:18 AM: Function.Module._load (internal/modules/cjs/loader.js:585:3)
9:54:18 AM: Use the --verbose option for deep traces
9:54:19 AM: Caching artifacts
9:54:19 AM: Started saving node modules
9:54:19 AM: Finished saving node modules
Can I ask which node modules folder is restored?
Second question - is it possible to specify additional folders to cache and restore. For example when doing yarn I would like to cache and restore ~/.cache/yarn folder, and for Cypress itself I would love to cache ~/.cache/cypress folder (that's where the binary is unzipped into)
I am trying to create cypress plugin locally in a forked
build-example-basicrepo (so I can run it on Netlify under https://app.netlify.com/sites/condescending-knuth-7cff53)my root package has plugin as a dev dependency
{ "name": "example-basic", "private": true, "version": "0.0.0", "description": "Example Netlify Build Site", "scripts": { "docs": "md-magic --path '**/*.md' --ignore 'node_modules'", "build": "mkdir -p build && cp src/index.html build", "postinstall": "echo nothing to do post NPM install" }, "author": "David Wells", "license": "MIT", "devDependencies": { "markdown-magic": "^1.0.0", "netlify-plugin-cypress": "file:plugins/cypress" }, "dependencies": { "@netlify/sitemap-plugin": "0.0.2" } }The plugin in
plugins/cypresshas its ownpackage.json{ "name": "netlify-plugin-cypress", "private": true, "version": "0.0.1", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC", "dependencies": { "cypress": "3.4.1" } }On the first deploy, plugin's dependencies ARE installed, for example in https://app.netlify.com/sites/condescending-knuth-7cff53/deploys/5da086c8bc913d00086e6fa9
There
package.jsonandpackage-lock.jsonfiles in both root and plugin's folders.When running the plugin requires
cypressnpm module like thisThe plugin works just fine, testing deployed site
On the second deploy though, NPM dependencies are not found, here is the build log
Can I ask which node modules folder is restored?
Second question - is it possible to specify additional folders to cache and restore. For example when doing
yarnI would like to cache and restore~/.cache/yarnfolder, and for Cypress itself I would love to cache~/.cache/cypressfolder (that's where the binary is unzipped into)