-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: improve handling of userland injected styles in component testing (
#16024) * feat(npm/react): do not clear head between tests * add a shared mount utils library * add readme * update dependencies * add mount utils to circle * change module Co-authored-by: Barthélémy Ledoux <bart@cypress.io>
- Loading branch information
1 parent
a6d504a
commit fe0b63c
Showing
16 changed files
with
321 additions
and
179 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
Empty file.
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,10 @@ | ||
# @cypress/mount-utils | ||
|
||
> **Note** this package is not meant to be used outside of cypress component testing. | ||
This librares exports some shared types and utility functions designed to build adapters for components frameworks. | ||
|
||
It is used in: | ||
|
||
- [`@cypress/react`](https://github.com/cypress-io/cypress/tree/develop/npm/react) | ||
- [`@cypress/vue`](https://github.com/cypress-io/cypress/tree/develop/npm/vue) |
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,28 @@ | ||
{ | ||
"name": "@cypress/mount-utils", | ||
"version": "0.0.0-development", | ||
"description": "Shared utilities for the various component testing adapters", | ||
"main": "dist/index.js", | ||
"scripts": { | ||
"build": "tsc", | ||
"build-prod": "tsc", | ||
"watch": "tsc -w" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"typescript": "^4.2.3" | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/cypress-io/cypress.git" | ||
}, | ||
"homepage": "https://github.com/cypress-io/cypress/tree/master/npm/mount-utils#readme", | ||
"bugs": "https://github.com/cypress-io/cypress/issues/new?template=1-bug-report.md", | ||
"publishConfig": { | ||
"access": "public" | ||
} | ||
} |
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,52 @@ | ||
{ | ||
"compilerOptions": { | ||
/* Basic Options */ | ||
"target": "es2015" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */, | ||
"module": "esnext" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */, | ||
"skipLibCheck": true, | ||
"lib": [ | ||
"es2015", | ||
"dom" | ||
] /* Specify library files to be included in the compilation: */, | ||
"allowJs": true /* Allow javascript files to be compiled. */, | ||
// "checkJs": true, /* Report errors in .js files. */ | ||
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ | ||
"declaration": true /* Generates corresponding '.d.ts' file. */, | ||
// "sourceMap": true, /* Generates corresponding '.map' file. */ | ||
// "outFile": "./", /* Concatenate and emit output to single file. */ | ||
"outDir": "dist" /* Redirect output structure to the directory. */, | ||
// "rootDir": "src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ | ||
// "removeComments": true, /* Do not emit comments to output. */ | ||
// "noEmit": true, /* Do not emit outputs. */ | ||
// "importHelpers": true, /* Import emit helpers from 'tslib'. */ | ||
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ | ||
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ | ||
|
||
/* Strict Type-Checking Options */ | ||
"strict": false /* Enable all strict type-checking options. */, | ||
// "noImplicitAny": true, | ||
|
||
/* Module Resolution Options */ | ||
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ | ||
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ | ||
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ | ||
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ | ||
// "typeRoots": [], /* List of folders to include type definitions from. */ | ||
"types": ["cypress"] /* Type declaration files to be included in compilation. */, | ||
"allowSyntheticDefaultImports": true /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */, | ||
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ | ||
|
||
/* Source Map Options */ | ||
// "sourceRoot": "./", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ | ||
// "mapRoot": "./", /* Specify the location where debugger should locate map files instead of generated locations. */ | ||
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ | ||
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ | ||
|
||
/* Experimental Options */ | ||
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ | ||
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ | ||
"esModuleInterop": true | ||
}, | ||
"include": ["src"], | ||
"exclude": ["node_modules", "*.js"] | ||
} |
79 changes: 79 additions & 0 deletions
79
npm/react/cypress/component/basic/styled-components/issue-15879.spec.js
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,79 @@ | ||
import * as React from 'react' | ||
import { mount } from '@cypress/react' | ||
import styled, { ThemeProvider } from 'styled-components' | ||
|
||
const lightest = '#FFFEFD' | ||
const light = '#FEFCF1' | ||
const darker = '#C49A03' | ||
const darkest = '#382E0A' | ||
|
||
export const theme = { | ||
primaryDark: darkest, | ||
primaryLight: lightest, | ||
primaryLightDarker: light, | ||
primaryHover: darker, | ||
} | ||
|
||
const styledComponentsStyle = 'margin-bottom:1rem' | ||
const Line = styled.div` | ||
${styledComponentsStyle} | ||
` | ||
|
||
export const SearchResults = (props) => { | ||
return ( | ||
<div> | ||
{props.results.map((result) => { | ||
return ( | ||
<Line> | ||
{result.title} | ||
</Line> | ||
) | ||
})} | ||
</div> | ||
) | ||
} | ||
|
||
const mountComponent = ({ results }, options) => { | ||
return mount( | ||
<ThemeProvider theme={theme}> | ||
<div style={{ margin: '6rem', maxWidth: '105rem' }}> | ||
<SearchResults results={results} /> | ||
</div> | ||
</ThemeProvider>, | ||
options, | ||
) | ||
} | ||
|
||
const inlineStyle = 'body { background: blue; }' | ||
const bulmaCDN = 'https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.2/css/bulma.css' | ||
|
||
describe('SearchResults', () => { | ||
it('should inject styles into <head>', () => { | ||
mountComponent({ | ||
results: [{ title: 'Org 1' }, { title: 'Org 2' }], | ||
}, | ||
{ | ||
stylesheets: [bulmaCDN], | ||
style: inlineStyle, | ||
}) | ||
|
||
cy.get('link').should('exist') | ||
cy.get('link').should('have.attr', 'href', bulmaCDN) | ||
}) | ||
|
||
it('style-components injected styles from previous test should not be cleaned up \ | ||
but styles and stylesheets in mount should be', () => { | ||
// style-components injected style should NOT have bene cleaned up | ||
cy.get('style').should('contain.text', styledComponentsStyle) | ||
|
||
// cleaned up inline <style> from previous test | ||
cy.get('style').should('not.contain.text', inlineStyle) | ||
|
||
// cleaned up bulma CDN link from previous test | ||
cy.get('link').should('not.exist') | ||
|
||
mountComponent({ | ||
results: [{ title: 'Org 1' }, { title: 'Org 2' }], | ||
}) | ||
}) | ||
}) |
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
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.