Skip to content
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

chore: Add eslint config to system-test project fixtures #25089

Merged
merged 5 commits into from
Dec 9, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
11 changes: 11 additions & 0 deletions system-tests/project-fixtures/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"plugins": [
"cypress"
],
"env": {
"cypress/globals": true
},
"rules": {
"mocha/no-global-tests": "off"
}
}
10 changes: 5 additions & 5 deletions system-tests/project-fixtures/cra/src/App.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logo from './logo.svg';
import './App.css';
import logo from './logo.svg'
import './App.css'

function App() {
function App () {
return (
<div className="App">
<header className="App-header">
Expand All @@ -19,7 +19,7 @@ function App() {
</a>
</header>
</div>
);
)
}

export default App;
export default App
12 changes: 6 additions & 6 deletions system-tests/project-fixtures/cra/src/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import React from 'react'
import ReactDOM from 'react-dom'
import './index.css'
import App from './App'

ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
);
document.getElementById('root'),
)
14 changes: 7 additions & 7 deletions system-tests/project-fixtures/next/cypress.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const path = require('path');
const path = require('path')

module.exports = {
component: {
Expand All @@ -10,12 +10,12 @@ module.exports = {
resolve: {
alias: {
'react': path.resolve(__dirname, './node_modules/react'),
}
}
}
}
},
},
},
},
},
// These tests should run quickly / fail quickly,
// since we intentionally causing error states for testing
defaultCommandTimeout: 1000
}
defaultCommandTimeout: 1000,
}
2 changes: 1 addition & 1 deletion system-tests/project-fixtures/next/pages/_app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import '../styles/globals.css'

function MyApp({ Component, pageProps }) {
function MyApp ({ Component, pageProps }) {
return <Component {...pageProps} />
}

Expand Down
2 changes: 1 addition & 1 deletion system-tests/project-fixtures/next/pages/api/hello.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction

export default function handler(req, res) {
export default function handler (req, res) {
res.status(200).json({ name: 'John Doe' })
}
4 changes: 2 additions & 2 deletions system-tests/project-fixtures/next/pages/index.cy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { mount } from "cypress/react"
import Index from "./index.js"
import { mount } from 'cypress/react'
import Index from './index.js'

describe('<Index />', () => {
it('renders', () => {
Expand Down
2 changes: 1 addition & 1 deletion system-tests/project-fixtures/next/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Head from 'next/head'
import Image from 'next/image'
import styles from '../styles/Home.module.css'

export default function Home() {
export default function Home () {
return (
<div className={styles.container}>
<Head>
Expand Down
4 changes: 2 additions & 2 deletions system-tests/project-fixtures/next/pages/styles.cy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { mount } from "cypress/react"
import Index from "./index.js"
import { mount } from 'cypress/react'
import Index from './index.js'

describe('<Index />', () => {
it('renders', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import Tutorial from './Tutorial.vue'
it('works', () => {
mount(Tutorial)
cy.contains('Nuxt')
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import { mount } from 'cypress/react'

import './backgroundColor.css'

Cypress.Commands.add('mount', mount)
Cypress.Commands.add('mount', mount)
6 changes: 3 additions & 3 deletions system-tests/project-fixtures/react/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {defineConfig} = require('vite')
const { defineConfig } = require('vite')

module.exports = defineConfig({
resolve: {
Expand All @@ -7,5 +7,5 @@ module.exports = defineConfig({
'react-dom': require.resolve('react-dom'),
},
},
logLevel: 'silent'
})
logLevel: 'silent',
})
4 changes: 2 additions & 2 deletions system-tests/project-fixtures/react/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const path = require('path')

/**
* @type {import('webpack').Configuration}
*/
Expand All @@ -24,6 +25,5 @@ module.exports = {
use: ['style-loader', 'css-loader'],
},
],
}
},
}

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mount } from "cypress/svelte";
import "../../src/styles.css"
import { mount } from 'cypress/svelte'
import '../../src/styles.css'

Cypress.Commands.add("mount", mount);
Cypress.Commands.add('mount', mount)
2 changes: 1 addition & 1 deletion system-tests/project-fixtures/svelte/src/App.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ it('should render with style', () => {
cy.get('.very-red').should('have.css', 'color', 'rgb(255, 0, 0)')
// Verify local styles
cy.get('.very-blue').should('have.css', 'color', 'rgb(0, 0, 255)')
})
})
3 changes: 1 addition & 2 deletions system-tests/project-fixtures/svelte/src/errors.cy.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Errors from './Errors.svelte'

describe('Errors', () => {

it('error on mount', () => {
cy.mount(Errors, { props: { throwError: true } })
})
Expand All @@ -20,4 +19,4 @@ describe('Errors', () => {
cy.mount(Errors)
cy.get('element-that-does-not-exist')
})
})
})
10 changes: 5 additions & 5 deletions system-tests/project-fixtures/svelte/src/main.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import App from "./App.svelte";
import "./styles.css";
import App from './App.svelte'
import './styles.css'

const app = new App({
target: document.getElementById("app"),
});
target: document.getElementById('app'),
})

export default app;
export default app
137 changes: 69 additions & 68 deletions system-tests/project-fixtures/svelte/src/mount.cy.js
Original file line number Diff line number Diff line change
@@ -1,98 +1,99 @@
import Counter from './Counter.svelte';
import Context from './Context.svelte';
import Store from './Store.svelte';
import { messageStore } from './store';
import Counter from './Counter.svelte'
import Context from './Context.svelte'
import Store from './Store.svelte'
import { messageStore } from './store'

describe('Svelte mount', () => {
it('mounts', () => {
cy.mount(Counter)
cy.contains('h1', 'Count is 0');
});
cy.contains('h1', 'Count is 0')
})

it('reacts to state changes', () => {
cy.mount(Counter);
cy.contains('h1', 'Count is 0');
cy.get('button').click();
cy.contains('h1', 'Count is 1');
});
cy.mount(Counter)
cy.contains('h1', 'Count is 0')
cy.get('button').click()
cy.contains('h1', 'Count is 1')
})

it('accepts props', () => {
cy.mount(Counter, { props: { count: 42 } });
cy.contains('h1', 'Count is 42');
});
cy.mount(Counter, { props: { count: 42 } })
cy.contains('h1', 'Count is 42')
})

it('accepts context', () => {
const payload = { msg: 'This value came from context!' };
const context = new Map();
context.set('myKey', payload);
const payload = { msg: 'This value came from context!' }
const context = new Map()

cy.mount(Context, { context });
cy.contains('h1', payload.msg);
});
context.set('myKey', payload)

cy.mount(Context, { context })
cy.contains('h1', payload.msg)
})

it('spies on outputs', () => {
cy.mount(Counter).then(({ component }) => {
component.$on('change', cy.spy().as('changeSpy'));
cy.get('button').click();
cy.get('@changeSpy').should('have.been.called');
});
});
component.$on('change', cy.spy().as('changeSpy'))
cy.get('button').click()
cy.get('@changeSpy').should('have.been.called')
})
})

it('anchors mounted component', () => {
cy.mount(Counter, { anchor: document.getElementById('anchor') });
cy.get('[data-cy-root]').children().last().should('have.id', 'anchor');
});
cy.mount(Counter, { anchor: document.getElementById('anchor') })
cy.get('[data-cy-root]').children().last().should('have.id', 'anchor')
})

it('reactive to writables', () => {
cy.mount(Store);
cy.contains('h1', 'Hello World!');
cy.mount(Store)
cy.contains('h1', 'Hello World!')

cy.get('input').clear().type('New Message');
cy.contains('h1', 'New Message');
cy.get('input').clear().type('New Message')
cy.contains('h1', 'New Message')

cy.then(() => messageStore.set('Written from spec'));
cy.contains('h1', 'Written from spec');
});
cy.then(() => messageStore.set('Written from spec'))
cy.contains('h1', 'Written from spec')
})

context('log', () => {
it('displays component name in mount log', () => {
cy.mount(Counter);

cy.wrap(Cypress.$(window.top.document.body)).within(() =>
cy
.contains('displays component name in mount log')
.closest('.collapsible')
.click()
.within(() =>
cy
.get('.command-name-mount')
.should('contain', 'mount<Counter ... />')
)
);
});
cy.mount(Counter)

cy.wrap(Cypress.$(window.top.document.body)).within(() => {
return cy
.contains('displays component name in mount log')
.closest('.collapsible')
.click()
.within(() => {
return cy
.get('.command-name-mount')
.should('contain', 'mount<Counter ... />')
})
})
})

it('does not display mount log', () => {
cy.mount(Counter, { log: false });

cy.wrap(Cypress.$(window.top.document.body)).within(() =>
cy
.contains('does not display mount log')
.closest('.collapsible')
.click()
.within(() => cy.get('.command-name-mount').should('not.exist'))
);
});
});

cy.mount(Counter, { log: false })

cy.wrap(Cypress.$(window.top.document.body)).within(() => {
return cy
.contains('does not display mount log')
.closest('.collapsible')
.click()
.within(() => cy.get('.command-name-mount').should('not.exist'))
})
})
})

it('throws error when receiving removed mounting option', () => {
Cypress.on('fail', (e) => {
expect(e.message).to.contain('The `styles` mounting option is no longer supported.')

return false
})

cy.mount(Counter, {
styles: `body { background: red; }`
cy.mount(Counter, {
styles: `body { background: red; }`,
})
})

Expand All @@ -103,17 +104,17 @@ describe('Svelte mount', () => {
})

it('should mount', () => {
cy.mount(Counter);
});
cy.mount(Counter)
})

it('should remove previous mounted component', () => {
cy.mount(Counter);
cy.mount(Counter)
cy.contains('h1', 'Count is 0')
cy.mount(Counter, {props: { count: 42 }})
cy.mount(Counter, { props: { count: 42 } })
cy.contains('h1', 'Count is 42')

cy.contains('h1', 'Count is 0').should('not.exist')
cy.get('[data-cy-root]').children().should('have.length', 2)
})
})
});
})
4 changes: 2 additions & 2 deletions system-tests/project-fixtures/svelte/src/store.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { writable } from "svelte/store";
import { writable } from 'svelte/store'

export const messageStore = writable("Hello World!");
export const messageStore = writable('Hello World!')
Loading