Skip to content

Commit

Permalink
Merge pull request #14940 from cypress-io/feat/resizeable-specs-list
Browse files Browse the repository at this point in the history
feat(component-testing): Make specs-list resizeable
  • Loading branch information
lmiller1990 authored Feb 8, 2021
2 parents 2891a51 + edcdd15 commit e71af5a
Show file tree
Hide file tree
Showing 15 changed files with 353 additions and 59 deletions.
33 changes: 33 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,29 @@ commands:
path: /tmp/artifacts
- store-npm-logs

run-runner-ct-integration-tests:
parameters:
browser:
description: browser shortname to target
type: string
percy:
description: enable percy
type: boolean
default: false
steps:
- attach_workspace:
at: ~/
- check-conditional-ci
- run:
command: |
cmd=$([[ <<parameters.percy>> == 'true' ]] && echo 'yarn percy exec --') || true
$cmd yarn workspace @packages/runner-ct run cy:run --browser <<parameters.browser>>
- store_test_results:
path: /tmp/cypress
- store_artifacts:
path: /tmp/artifacts
- store-npm-logs

run-e2e-tests:
parameters:
browser:
Expand Down Expand Up @@ -851,6 +874,13 @@ jobs:
- run-runner-integration-tests:
browser: firefox

runner-ct-integration-tests-chrome:
<<: *defaults
steps:
- run-runner-ct-integration-tests:
browser: chrome
percy: true

driver-integration-tests-chrome:
<<: *defaults
parallelism: 5
Expand Down Expand Up @@ -1698,6 +1728,9 @@ linux-workflow: &linux-workflow
- runner-integration-tests-firefox:
requires:
- build
- runner-ct-integration-tests-chrome:
requires:
- build

## TODO: add these back in when flaky tests are fixed
# - driver-integration-tests-electron:
Expand Down
46 changes: 46 additions & 0 deletions packages/runner-ct/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"plugins": [
"cypress",
"@cypress/dev"
],
"extends": [
"plugin:@cypress/dev/general",
"plugin:@cypress/dev/tests",
"plugin:@cypress/dev/react"
],
"parser": "@typescript-eslint/parser",
"env": {
"cypress/globals": true
},
"rules": {
"react/jsx-filename-extension": [
"warn",
{
"extensions": [
".js",
".jsx",
".tsx"
]
}
]
},
"overrides": [
{
"files": [
"lib/*"
],
"rules": {
"no-console": 1
}
},
{
"files": [
"**/*.json"
],
"rules": {
"quotes": "off",
"comma-dangle": "off"
}
}
]
}
88 changes: 88 additions & 0 deletions packages/runner-ct/cypress/component/App.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/// <reference types="@percy/cypress" />
import React from 'react'
import { mount } from '@cypress/react'
import App from '../../src/app/app'
import State from '../../src/lib/state'
import '@packages/runner/src/main.scss'

class FakeEventManager {
start = () => { }
on = () => { }
stop = () => {}
notifyRunningSpec = () => { }
}

describe('App', () => {
it('renders App', () => {
cy.viewport(1000, 500)
const state = new State({
reporterWidth: 500,
spec: null,
specs: [{ relative: '/test.js', absolute: 'root/test.js', name: 'test.js' }],
})

mount(
<App
state={state}
// @ts-ignore - this is difficult to stub. Real one breaks things.
eventManager={new FakeEventManager()}
config={{ projectName: 'Project', env: {} }}
/>,
)

cy.percySnapshot()
})

context('specs-list resizing', () => {
beforeEach(() => {
cy.viewport(1000, 500)
const state = new State({
reporterWidth: 500,
spec: null,
specs: [{ relative: '/test.js', absolute: 'root/test.js', name: 'test.js' }],
})

mount(
<App
state={state}
// @ts-ignore - this is difficult to stub. Real one breaks things.
eventManager={new FakeEventManager()}
config={{ projectName: 'Project', env: {} }}
/>,
)
})

it('closes the spec list when selecting a spec', () => {
cy.get('[data-cy=specs-list-resize-box').should('have.css', 'width', '300px')

cy.get('[data-cy=resizer]').trigger('mousedown', 'center')
cy.get('[data-cy=resizer]').trigger('mousemove', 'center', {
clientX: 450,
})

cy.get('[data-cy=resizer]').trigger('mouseup', 'center')

cy.get('[data-cy=specs-list-resize-box').should('have.css', 'width', '425px')
})

it('restore specs list width after closing and reopen', () => {
cy.get('[data-cy=resizer]').trigger('mousedown', 'center')
cy.get('[data-cy=resizer]').trigger('mousemove', 'center', {
clientX: 500,
})

cy.get('[data-cy=resizer]').trigger('mouseup', 'center')
cy.get('[data-cy=specs-list-resize-box').should('have.css', 'width', '475px')

cy.get('[aria-label="Open the menu"').click()
cy.get('[data-cy=specs-list]').then(([el]) => {
// for some reason should("not.be.visible") doesn't work here so ensure that specs list was outside of screen
expect(el.getBoundingClientRect().x).to.be.lessThan(0)
})

cy.get('[aria-label="Open the menu"').click()

cy.get('[data-cy=specs-list-resize-box').should('have.css', 'width', '475px')
})
})
})
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* global cy */
import React from 'react'
import { mount } from '@cypress/react'
import { SpecList } from '../../../src/SpecList'
Expand Down
26 changes: 22 additions & 4 deletions packages/runner-ct/cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,35 @@
/// <reference types="cypress" />
const { startDevServer } = require('@cypress/webpack-dev-server')
const path = require('path')
const percyHealthCheck = require('@percy/cypress/task')
const { startDevServer } = require('@cypress/webpack-dev-server')

function injectStylesInlineForPercyInPlace (webpackConfig) {
webpackConfig.module.rules = webpackConfig.module.rules.map((rule) => {
if (rule?.use[0]?.loader.includes('mini-css-extract-plugin')) {
return {
...rule,
use: [{
loader: 'style-loader',
}],
}
}

return rule
})
}
/**
* @type {Cypress.PluginConfig}
*/
module.exports = (on, config) => {
on('task', percyHealthCheck)
on('dev-server:start', (options) => {
// yarn tsc webpack.config.ts --esModuleInterop
const config = path.resolve(__dirname, '../../webpack.config.js')
/** @type {import('webpack').Configuration} */
const { default: webpackConfig } = require(path.resolve(__dirname, '..', '..', 'webpack.config.ts'))

injectStylesInlineForPercyInPlace(webpackConfig)

return startDevServer({
webpackConfig: require(config).default,
webpackConfig,
options,
})
})
Expand Down
1 change: 1 addition & 0 deletions packages/runner-ct/cypress/support/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

// Import commands.js using ES2015 syntax:
import './commands'
import '@percy/cypress'

// Alternatively you can use CommonJS syntax:
// require('./commands')
3 changes: 3 additions & 0 deletions packages/runner-ct/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"build": "webpack",
"build-prod": "cross-env NODE_ENV=production yarn build && tsc",
"clean-deps": "rm -rf node_modules",
"cy:open": "node ../../scripts/cypress.js open-ct --project ${PWD}",
"cy:run": "node ../../scripts/cypress.js run-ct --project ${PWD}",
"postinstall": "echo '@packages/runner needs: yarn build'",
"test-unit": "ts-mocha --config ./test/.mocharc.js --require './test/setup.js'",
"watch": "webpack --watch --progress --config webpack.config.ts"
Expand Down Expand Up @@ -40,6 +42,7 @@
"@babel/core": "^7.12.3",
"@babel/preset-env": "^7.12.1",
"@packages/driver": "0.0.0-development",
"@percy/cypress": "2.3.4",
"@types/sockjs-client": "1.1.0",
"babel-loader": "8.1.0",
"clean-webpack-plugin": "^3.0.0",
Expand Down
1 change: 0 additions & 1 deletion packages/runner-ct/render-target.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* globals document */
import $ from 'cash-dom'

function appendTargetIfNotExists (id, tag = 'div', parent = document.body) {
Expand Down
7 changes: 6 additions & 1 deletion packages/runner-ct/src/SpecList/SpecList.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useState } from 'react'

import cs from 'classnames'
import { SpecItem } from './SpecItem'
import { OnSelectSpec } from './SpecFileItem'
import { SearchSpec } from './components/SearchSpec'
Expand All @@ -10,6 +11,7 @@ interface SpecsListProps {
selectedSpecs: string[]
specs: Cypress.Cypress['spec'][]
onSelectSpec: OnSelectSpec
disableTextSelection: boolean
}

export const SpecList: React.FC<SpecsListProps> = (props) => {
Expand All @@ -23,7 +25,10 @@ export const SpecList: React.FC<SpecsListProps> = (props) => {
value={search}
onSearch={setSearch}
/>
<ul className="specs-list">
<ul
data-cy="specs-list"
className={cs('specs-list', { 'specs-list_text-selection-disabled': props.disableTextSelection })}
>
{
hierarchy.map((item) => (
<SpecItem
Expand Down
4 changes: 4 additions & 0 deletions packages/runner-ct/src/SpecList/spec-list.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@
width: calc(100% - 40px);
height: calc(100% - 10px);
overflow-y: auto;

&.specs-list_text-selection-disabled {
user-select: none;
}
}
64 changes: 29 additions & 35 deletions packages/runner-ct/src/app/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,57 +12,51 @@ main.app-ct {
}

.menu-toggle {
padding-top: $specs-list-padding;
z-index: 2;
:hover {
cursor: pointer;
}
}

.specs-list-container {
$width: 300px;
$header-height: 61px;
display: grid;
grid-template-rows: min-content;
grid-gap: $specs-list-padding;
padding-left: $specs-list-padding;
padding-top: $specs-list-padding;
z-index: 9999;
position: absolute; // TODO: Make sure global styles are properly handled
box-shadow: $box-shadow-closest;
.specs-list-drawer {
$header-height: 40px;

will-change: transform;
background: #f6f6f6;
width: $width;
width: auto;
top: 0;
left: calc(-1 * (#{$width} - #{$specs-list-padding}));
height: calc(100vh - 20px);
left: 0;
z-index: 9999;
position: absolute; // TODO: Make sure global styles are properly handled
box-shadow: $box-shadow-closest;
transition: ease-in-out 0.2s;
transform: translateX(0px);

nav {

position: absolute;
height: $header-height;
right: $font-size;
transform: translateX(0px);
padding-left: $specs-list-padding;
padding-top: $specs-list-padding;

display: flex;
align-items: center;
justify-content: center;
.specs-list-container {
display: grid;
grid-template-rows: min-content;
grid-gap: $specs-list-padding;
height: calc(100vh - 20px);

nav {
position: absolute;
height: $header-height;
right: $font-size;
transform: translateX(0px);
display: flex;
align-items: center;
justify-content: center;

a {
color: unset;
a {
color: unset;

:hover, :active {
color: gray;
:hover, :active {
color: gray;
}
}

}
}

&__open {
transform: translateX(calc(#{$width} - 20px));
}
}

.app-wrapper {
Expand Down
Loading

4 comments on commit e71af5a

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on e71af5a Feb 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/6.6.0/circle-develop-e71af5aaa8f9e2a328a924640d3fa4e9a23c79ac/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on e71af5a Feb 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/6.5.0/appveyor-develop-e71af5aaa8f9e2a328a924640d3fa4e9a23c79ac/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on e71af5a Feb 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 ia32 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/6.5.0/appveyor-develop-e71af5aaa8f9e2a328a924640d3fa4e9a23c79ac/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on e71af5a Feb 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/6.6.0/circle-develop-e71af5aaa8f9e2a328a924640d3fa4e9a23c79ac/cypress.tgz

Please sign in to comment.