-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: find local files better (#197)
* chore: refactor * adding detecting folder that matches current folder root * move utility functions * feat: find matching folder example * add docker paths example to circleci * exclude utils file from coverage
- Loading branch information
Showing
16 changed files
with
460 additions
and
53 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
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,38 @@ | ||
# example-docker-paths | ||
|
||
In this example, the source files are "instrumented" as if they were instrumented inside a Docker container. Still, Cypress code coverage plugin should find the matching current folder where same files exist and update `.nyc_output/out.json` file before generating reports. | ||
|
||
Source files from `app` folder were instrumented into `dist` folder with command | ||
|
||
```shell | ||
$ npx nyc instrument app dist | ||
``` | ||
|
||
Then the `index.html` file was copied into `dist` folder. | ||
|
||
Then the source paths in [dist/main.js](dist/main.js) and [dist/second.js](dist/second.js) were changed to non-existent prefix folder `/var/www/test/site`. | ||
|
||
When Cypress runs, the `.nyc_output/out.json` is updated, so the path is valid local path like: | ||
|
||
``` | ||
{ | ||
"/var/www/test/site/app/main.js": { | ||
"path": "/Users/gleb/git/code-coverage/examples/docker-paths/app/main.js", | ||
"statementMap": { | ||
... | ||
``` | ||
|
||
And the report has valid HTML with sources | ||
|
||
![All files](images/files.png) | ||
|
||
![Single file](images/file.png) | ||
|
||
**Note:** remember to remove existing `.nyc_output` folder if running Cypress in non-interactive mode `rm -rf .nyc_output/`. | ||
|
||
When running with [debug logs](https://github.com/cypress-io/code-coverage#debugging) you should see messages: | ||
|
||
``` | ||
found common folder /var/www/test/site that matches | ||
current working directory /Users/gleb/git/code-coverage/examples/docker-paths | ||
``` |
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,17 @@ | ||
<body> | ||
Page body | ||
<script src="main.js"></script> | ||
<script src="second.js"></script> | ||
<script> | ||
// use functions creates in "main.js" | ||
if (add(2, 3) !== 5) { | ||
throw new Error('wrong addition') | ||
} | ||
if (sub(2, 3) !== -1) { | ||
throw new Error('wrong subtraction') | ||
} | ||
if (reverse('foo') !== 'oof') { | ||
throw new Error('wrong string reverse') | ||
} | ||
</script> | ||
</body> |
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,3 @@ | ||
window.add = (a, b) => a + b | ||
|
||
window.sub = (a, b) => a - b |
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,7 @@ | ||
// this file should be excluded from the final coverage numbers | ||
// using "nyc.exclude" list in package.json | ||
window.reverse = s => | ||
s | ||
.split('') | ||
.reverse() | ||
.join('') |
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,5 @@ | ||
{ | ||
"pluginsFile": "../../plugins", | ||
"supportFile": "../../support", | ||
"fixturesFolder": false | ||
} |
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 @@ | ||
/// <reference types="cypress" /> | ||
describe('docker-paths', () => { | ||
it('works', () => { | ||
cy.visit('dist/index.html') | ||
cy.contains('Page body') | ||
|
||
cy.window() | ||
.invoke('reverse', 'super') | ||
.should('equal', 'repus') | ||
}) | ||
}) |
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,17 @@ | ||
<body> | ||
Page body | ||
<script src="main.js"></script> | ||
<script src="second.js"></script> | ||
<script> | ||
// use functions creates in "main.js" | ||
if (add(2, 3) !== 5) { | ||
throw new Error('wrong addition') | ||
} | ||
if (sub(2, 3) !== -1) { | ||
throw new Error('wrong subtraction') | ||
} | ||
if (reverse('foo') !== 'oof') { | ||
throw new Error('wrong string reverse') | ||
} | ||
</script> | ||
</body> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,14 @@ | ||
{ | ||
"name": "example-docker-paths", | ||
"private": true, | ||
"version": "1.0.0", | ||
"description": "Instrumented files in Docker container are found locally", | ||
"main": "index.js", | ||
"scripts": { | ||
"cy:open": "../../node_modules/.bin/cypress open", | ||
"cy:run": "../../node_modules/.bin/cypress run" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC" | ||
} |
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
Oops, something went wrong.