-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/elaichenkov/cy-verify-dow…
- Loading branch information
Showing
15 changed files
with
8,777 additions
and
1,712 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: npm | ||
directory: "/" | ||
schedule: | ||
interval: "weekly" | ||
time: "11:00" | ||
open-pull-requests-limit: 10 | ||
versioning-strategy: increase-if-necessary |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# For most projects, this workflow file will not need changing; you simply need | ||
# to commit it to your repository. | ||
# | ||
# You may wish to alter this file to override the set of languages analyzed, | ||
# or to provide custom queries or build logic. | ||
# | ||
# ******** NOTE ******** | ||
# We have attempted to detect the languages in your repository. Please check | ||
# the `language` matrix defined below to confirm you have the correct set of | ||
# supported CodeQL languages. | ||
# | ||
name: "CodeQL" | ||
|
||
on: | ||
push: | ||
branches: [ master ] | ||
pull_request: | ||
# The branches below must be a subset of the branches above | ||
branches: [ master ] | ||
schedule: | ||
- cron: '43 18 * * 6' | ||
|
||
jobs: | ||
analyze: | ||
name: Analyze | ||
runs-on: ubuntu-latest | ||
permissions: | ||
actions: read | ||
contents: read | ||
security-events: write | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
language: [ 'javascript' ] | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
# Initializes the CodeQL tools for scanning. | ||
- name: Initialize CodeQL | ||
uses: github/codeql-action/init@v2 | ||
with: | ||
languages: ${{ matrix.language }} | ||
# If you wish to specify custom queries, you can do so here or in a config file. | ||
# By default, queries listed here will override any specified in a config file. | ||
# Prefix the list here with "+" to use these queries and those in the config file. | ||
# queries: ./path/to/local/query, your-org/your-repo/queries@main | ||
|
||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java). | ||
# If this step fails, then you should remove it and run the build manually (see below) | ||
- name: Autobuild | ||
uses: github/codeql-action/autobuild@v2 | ||
|
||
# ℹ️ Command-line programs to run using the OS shell. | ||
# 📚 https://git.io/JvXDl | ||
|
||
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines | ||
# and modify them (or add more) to build your code if your project | ||
# uses a compiled language | ||
|
||
#- run: | | ||
# make bootstrap | ||
# make release | ||
|
||
- name: Perform CodeQL Analysis | ||
uses: github/codeql-action/analyze@v2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,107 @@ | ||
# cy-verify-downloads  | ||
[](https://vshymanskyy.github.io/StandWithUkraine) | ||
|
||
This is a Cypress custom command to wait and to verify that a file has been successfully downloaded. | ||
# cy-verify-downloads  [](https://www.npmjs.com/package/cy-verify-downloads) | ||
|
||
<div align="center"> | ||
<img | ||
alt="logo" | ||
src="./assets/cy.verify.png" | ||
/> | ||
<p>Custom Cypress command to wait and verify that file is downloaded.</p> | ||
</div> | ||
|
||
## Installation | ||
|
||
```shell | ||
npm i -D cy-verify-downloads | ||
``` | ||
|
||
## Usage | ||
## Extend Cypress command | ||
|
||
cy-verify-downloads extends Cypress' cy command. | ||
This package extends Cypress' `cy` command. | ||
|
||
So, you need to add this line to your project's `cypress/support/commands.js`: | ||
**For Cypress v10+:** | ||
|
||
Add this line to your project's `cypress/support/e2e.js`: | ||
|
||
```javascript | ||
require('cy-verify-downloads').addCustomCommand(); | ||
``` | ||
|
||
Then you need to add the following lines of code to your project's `cypress.config.js`: | ||
|
||
And add the following lines to your project's `cypress/plugins/index.js`: | ||
```javascript | ||
const { verifyDownloadTasks } = require('cy-verify-downloads'); | ||
|
||
module.exports = defineConfig({ | ||
e2e: { | ||
setupNodeEvents(on, config) { | ||
on('task', verifyDownloadTasks); | ||
}, | ||
}, | ||
}); | ||
``` | ||
|
||
**For Cucumber:** | ||
|
||
Additionally, you may need to install and add node polyfill in your `support/e2e.js` file: | ||
|
||
1. Install the polyfill module: | ||
|
||
```bash | ||
npm i -D @esbuild-plugins/node-modules-polyfill | ||
``` | ||
2. Import the following code in your `support/e2e.js` file: | ||
|
||
```js | ||
const { NodeModulesPolyfillPlugin } = require('@esbuild-plugins/node-modules-polyfill'); | ||
``` | ||
|
||
3. Add the following code in your `plugins` property: | ||
|
||
```js | ||
module.exports = defineConfig({ | ||
e2e: { | ||
async setupNodeEvents(on, config) { | ||
const bundler = createBundler({ | ||
// add polyfill ⬇ NodeModulesPolyfillPlugin | ||
plugins: [NodeModulesPolyfillPlugin(), createEsbuildPlugin(config)], | ||
}); | ||
} | ||
} | ||
}); | ||
``` | ||
Moreover, you can take a look at the [comment](https://github.com/elaichenkov/cy-verify-downloads/issues/51#issuecomment-1237978973) with detailed example of adding node polyfill in your config. | ||
|
||
**For Cypress v9:** | ||
|
||
So, you need to add this line to your project's `cypress/support/commands.js`: | ||
|
||
```javascript | ||
require('cy-verify-downloads').addCustomCommand(); | ||
``` | ||
|
||
And add the following lines to your project's `cypress/plugins/index.js`: | ||
|
||
```javascript | ||
const { isFileExist } = require('cy-verify-downloads'); | ||
const { verifyDownloadTasks } = require('cy-verify-downloads'); | ||
|
||
module.exports = (on, config) => { | ||
on('task', { | ||
isFileExist | ||
}) | ||
on('task', verifyDownloadTasks) | ||
} | ||
``` | ||
|
||
## Usage | ||
|
||
Then, in your test, you can use it like this: | ||
|
||
```javascript | ||
cy.verifyDownload('picture.png'); | ||
|
||
// verify download by file extension or partial filename | ||
cy.verifyDownload('.png', { contains: true }); | ||
cy.verifyDownload('pic', { contains: true }); | ||
|
||
// or increase timeout | ||
cy.verifyDownload('archive.zip', { timeout: 25000 }); | ||
|
||
|
@@ -48,6 +114,7 @@ cy.verifyDownload('archive.zip', { timeout: 25000, interval: 600 }); | |
 | ||
|
||
To enable IntelliSense information and autocomplete you have to include types in the `tsconfig.json` file: | ||
|
||
```json | ||
{ | ||
"compilerOptions": { | ||
|
@@ -57,7 +124,9 @@ To enable IntelliSense information and autocomplete you have to include types in | |
``` | ||
|
||
## Author | ||
|
||
Yevhen Laichenkov <[email protected]> | ||
|
||
## License | ||
|
||
[MIT](LICENSE) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const { defineConfig } = require('cypress'); | ||
const { verifyDownloadTasks } = require('./src/index'); | ||
|
||
module.exports = defineConfig({ | ||
e2e: { | ||
setupNodeEvents(on, config) { | ||
on('task', verifyDownloadTasks); | ||
}, | ||
baseUrl: 'http://localhost:8039', | ||
}, | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
describe('verify download functionality', () => { | ||
beforeEach(() => { | ||
cy.visit('/'); | ||
}); | ||
|
||
it('downloads small file', () => { | ||
cy.get('[data-cy="small"]').click(); | ||
|
||
cy.verifyDownload('small-file-10MB.zip'); | ||
}); | ||
|
||
it('downloads large file', () => { | ||
cy.get('[data-cy="large"]').click(); | ||
|
||
cy.verifyDownload('large-file-100MB.zip', { timeout: 55000, interval: 500 }); | ||
}); | ||
|
||
it('downloads with contains option', () => { | ||
cy.exec(`rm -rf ${Cypress.config('downloadsFolder')}`); | ||
cy.get('[data-cy="large"]').click(); | ||
|
||
cy.verifyDownload('large-file-100MB', { contains: true }); | ||
}); | ||
|
||
it('downloads file with extension and contains option', () => { | ||
cy.exec(`rm -rf ${Cypress.config('downloadsFolder')}`); | ||
cy.get('[data-cy="large"]').click(); | ||
|
||
cy.verifyDownload('large-file-100MB.zip', { contains: true }); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
Oops, something went wrong.