Skip to content

feat: add skip=true flag to postBuild tests #105

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

Merged
merged 2 commits into from
Feb 4, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ How to [code a plugin](https://github.com/netlify/build/blob/master/docs/creatin

End-to-end tests are in folder [tests](tests) and they use this [plugin locally](https://github.com/netlify/build/blob/master/README.md#using-a-local-plugin) and build each subfolder using Netlify CLI on CircleCI. You can find the test recordings at [Cypress Dashboard](https://dashboard.cypress.io/projects/ixroqc/)

To run locally:

- `npx netlify link` once
- from every subfolder of `tests` execute `npm run build`

### Authentication (local)

- use `netlify-cli` to authenticate locally. It will also create a local site and store its ID in `.netlify` folder (ignored by `git`)
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,17 @@ Parameters you can place into `preBuild` inputs: `start`, `wait-on`, `wait-on-ti

See [netlify-plugin-prebuild-example](https://github.com/cypress-io/netlify-plugin-prebuild-example) repo

### skipping tests

If you are testing the site before building it, you probably want to skip testing it after the build. See [tests/test-prebuild-only](./tests/test-prebuild-only/netlify.toml):

```toml
[[plugins]]
package = "netlify-plugin-cypress"
[plugins.inputs]
skip = true
```

### parallelization

Running tests in parallel **is not supported** because Netlify plugin system runs on a single machine. Thus you can record the tests on Cypress Dashboard, but not run tests in parallel. If Netlify expands its build offering by allowing multiple build machines, we could take advantage of it and run tests in parallel.
Expand Down
17 changes: 17 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,19 @@ jobs:
environment:
DEBUG: netlify-plugin-cypress

'test-prebuild-only':
executor: cypress/base-12-14-0
steps:
# all dependencies were installed in previous job
- attach_workspace:
at: ~/
- run:
name: Netlify Build 🏗
command: npx netlify build
working_directory: tests/test-prebuild-only
environment:
DEBUG: netlify-plugin-cypress

routing:
executor: cypress/base-12-14-0
steps:
Expand Down Expand Up @@ -107,6 +120,9 @@ workflows:
- 'test-twice':
requires:
- cypress/install
- 'test-prebuild-only':
requires:
- cypress/install
- routing:
requires:
- cypress/install
Expand All @@ -117,6 +133,7 @@ workflows:
- 'recommended test'
- 'recording test'
- 'test-twice'
- 'test-prebuild-only'
- 'routing'
filters:
branches:
Expand Down
3 changes: 3 additions & 0 deletions manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ inputs:
- name: group
- name: tag
- name: spa
# by default run the tests
- name: skip
default: false

# tells the plugin how to start the server using custom command
# and waiting for an url, record to the dashboard, tag, etc
Expand Down
6 changes: 6 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,12 @@ module.exports = {
debugVerbose('postBuild arg %o', arg)
debug('cypress plugin postBuild inputs %o', arg.inputs)

const skipTests = Boolean(arg.inputs.skip)
if (skipTests) {
console.log('Skipping tests because skip=true')
return
}

const fullPublishFolder = arg.constants.PUBLISH_DIR
debug('folder to publish is "%s"', fullPublishFolder)

Expand Down
7 changes: 7 additions & 0 deletions tests/test-prebuild-only/cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"pluginsFile": false,
"supportFile": false,
"fixturesFolder": false,
"baseUrl": "http://localhost:5000",
"projectId": "ixroqc"
}
5 changes: 5 additions & 0 deletions tests/test-prebuild-only/cypress/integration/spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// <reference types="cypress" />
it('loads page', () => {
cy.visit('/')
cy.contains('Placeholder').should('be.visible')
})
28 changes: 28 additions & 0 deletions tests/test-prebuild-only/netlify.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[build]
command = "echo 'Netlify build command ...'"
publish = "public"

[build.environment]
# cache Cypress binary in local "node_modules" folder
# so Netlify caches it
CYPRESS_CACHE_FOLDER = "./node_modules/CypressBinary"
# set TERM variable for terminal output
TERM = "xterm"

[[plugins]]
# local Cypress plugin will test our site after it is built
# in production, please use: package = "netlify-plugin-cypress"
package = "../../"

# run Cypress tests once on the site before it is built
# and do not run the tests after it was built

# let's run tests against development server
[plugins.inputs.preBuild]
start = 'npx serve public'
wait-on = 'http://localhost:5000'
wait-on-timeout = '30' # seconds

# and skip tests after building it
[plugins.inputs]
skip = true
1 change: 1 addition & 0 deletions tests/test-prebuild-only/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<body>Placeholder</body>