Skip to content

Commit

Permalink
Merge pull request #17951 from cypress-io/chore/esm-driver
Browse files Browse the repository at this point in the history
chore: switching @packages/driver to be esm
  • Loading branch information
JessicaSachs authored Sep 7, 2021
2 parents d8796bc + 9013388 commit e216ae2
Show file tree
Hide file tree
Showing 175 changed files with 7,114 additions and 6,387 deletions.
1 change: 1 addition & 0 deletions packages/driver/cypress.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"projectId": "ypt4pf",
"baseUrl": "http://localhost:3500",
"testFiles": "**/*",
"hosts": {
"*.foobar.com": "127.0.0.1"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { $ } = Cypress.$Cypress
const { _ } = Cypress
const { $ } = window.Cypress.$Cypress
const { _ } = window.Cypress

describe('src/cy/commands/actions/scroll', () => {
before(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ describe('src/cy/commands/actions/select', () => {
expect($select.val()).to.equal('same')
expect($select.find('option:selected')).to.have.text('Uhura')
expect($select[0].selectedIndex).to.equal(2)
expect($select[0].selectedOptions[0]).to.eql($select.find('option:selected')[0])
})
})

Expand All @@ -74,7 +73,6 @@ describe('src/cy/commands/actions/select', () => {
expect($select.val()).to.equal('same')
expect($select.find('option:selected')).to.have.text('Uhura')
expect($select[0].selectedIndex).to.equal(2)
expect($select[0].selectedOptions[0]).to.eql($select.find('option:selected')[0])
})
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { $ } = Cypress
const $SnapshotsCss = require('../../../src/cy/snapshots_css')
const $SnapshotsCss = require('../../../src/cy/snapshots_css').default

const normalizeStyles = (styles) => {
return styles
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const browserProps = require('@packages/driver/src/cypress/browser')
import browserProps from '@packages/driver/src/cypress/browser'

describe('src/cypress/browser', () => {
beforeEach(function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import _ from 'lodash'
import $Command from '../../../src/cypress/command'

import { create } from '../../../src/cypress/command_queue'
import $CommandQueue from '../../../src/cypress/command_queue'

const createCommand = (props = {}) => {
return $Command.create(_.extend({
Expand Down Expand Up @@ -31,7 +30,7 @@ describe('src/cypress/command_queue', () => {
const isCy = () => {}

beforeEach(() => {
queue = create(state, timeouts, stability, cleanup, fail, isCy)
queue = $CommandQueue.create(state, timeouts, stability, cleanup, fail, isCy)

queue.add(createCommand({
name: 'get',
Expand Down
4 changes: 2 additions & 2 deletions packages/driver/cypress/integration/cypress/downloads_spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { create } from '../../../src/cypress/downloads'
import $Downloads from '../../../src/cypress/downloads'

describe('src/cypress/downloads', () => {
let log
Expand All @@ -17,7 +17,7 @@ describe('src/cypress/downloads', () => {
snapshot = cy.stub().returns({ end })
log = cy.stub().returns({ snapshot })

downloads = create({ log })
downloads = $Downloads.create({ log })
})

context('#start', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
const { allowTsModuleStubbing } = require('../../support/helpers')
// @ts-nocheck

import { allowTsModuleStubbing } from '../../support/helpers'

allowTsModuleStubbing()

const $stackUtils = require('@packages/driver/src/cypress/stack_utils')
const $errUtils = require('@packages/driver/src/cypress/error_utils')
const $errorMessages = require('@packages/driver/src/cypress/error_messages').default
import $stackUtils from '@packages/driver/src/cypress/stack_utils'
import $errUtils from '@packages/driver/src/cypress/error_utils'
import $errorMessages from '@packages/driver/src/cypress/error_messages'

describe('driver/src/cypress/error_utils', () => {
context('.modifyErrMsg', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/driver/cypress/integration/cypress/log_spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const $Log = require('@packages/driver/src/cypress/log')
const $Log = require('@packages/driver/src/cypress/log').default

describe('src/cypress/log', function () {
context('#snapshot', function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const $networkUtils = require('@packages/driver/src/cypress/network_utils')
const $networkUtils = require('@packages/driver/src/cypress/network_utils').default

describe('src/cypress/network_utils', () => {
context('#fetch', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const Promise = require('bluebird')
const $scriptUtils = require('@packages/driver/src/cypress/script_utils')
const $networkUtils = require('@packages/driver/src/cypress/network_utils')
const $sourceMapUtils = require('@packages/driver/src/cypress/source_map_utils')
const $scriptUtils = require('@packages/driver/src/cypress/script_utils').default
const $networkUtils = require('@packages/driver/src/cypress/network_utils').default
const $sourceMapUtils = require('@packages/driver/src/cypress/source_map_utils').default

describe('src/cypress/script_utils', () => {
context('#runScripts', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { SelectorPlayground, $ } = Cypress
const { $ } = window.Cypress.$Cypress
const SelectorPlayground = Cypress.SelectorPlayground

const SELECTOR_DEFAULTS = [
'data-cy', 'data-test', 'data-testid', 'id', 'class', 'tag', 'attributes', 'nth-child',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
const { SourceMapConsumer } = require('source-map')
import {
extractSourceMap,
getSourceContents,
getSourcePosition,
initializeSourceMapConsumer,
} from '@packages/driver/src/cypress/source_map_utils'
import $sourceMapUtils from '@packages/driver/src/cypress/source_map_utils'

const _ = Cypress._
const { encodeBase64Unicode } = Cypress.utils
Expand Down Expand Up @@ -51,19 +46,19 @@ const file2 = createFile('file2')
describe('driver/src/cypress/source_map_utils', () => {
context('.extractSourceMap', () => {
it('returns null if there is no source map embedded', () => {
const sourceMap = extractSourceMap(file2, testContent)
const sourceMap = $sourceMapUtils.extractSourceMap(file2, testContent)

expect(sourceMap).to.be.null
})

it('returns null if it is not an inline map', () => {
const sourceMap = extractSourceMap(file2, `${testContent}\n\/\/# sourceMappingURL=foo.map`)
const sourceMap = $sourceMapUtils.extractSourceMap(file2, `${testContent}\n\/\/# sourceMappingURL=foo.map`)

expect(sourceMap).to.be.null
})

it('returns source map when content has an inline map', () => {
const sourceMap = extractSourceMap(file1, fileContents)
const sourceMap = $sourceMapUtils.extractSourceMap(file1, fileContents)

expect(sourceMap).to.be.eql(sourceMap)
})
Expand All @@ -76,7 +71,7 @@ describe('driver/src/cypress/source_map_utils', () => {
const timeLimit = 10
const startTime = Date.now()

extractSourceMap(file1, fileContents)
$sourceMapUtils.extractSourceMap(file1, fileContents)

const endTime = Date.now()

Expand All @@ -86,39 +81,39 @@ describe('driver/src/cypress/source_map_utils', () => {

// https://github.com/cypress-io/cypress/issues/7481
it('does not garble utf-8 characters', () => {
const sourceMap = extractSourceMap(file1, fileContents)
const sourceMap = $sourceMapUtils.extractSourceMap(file1, fileContents)

expect(sourceMap.sourcesContent[1]).to.include('サイプリスは一番')
})
})

context('.getSourceContents', () => {
before(() => {
return initializeSourceMapConsumer(file1, sourceMap)
return $sourceMapUtils.initializeSourceMapConsumer(file1, sourceMap)
})

it('provides source contents for given file', () => {
const contents = getSourceContents(file1.fullyQualifiedUrl, file1.relative)
const contents = $sourceMapUtils.getSourceContents(file1.fullyQualifiedUrl, file1.relative)

expect(contents).to.equal(testContent)
})

it('returns null if no source map consumer can be found', () => {
expect(getSourceContents('does/not/exist', file1.relative)).to.be.null
expect($sourceMapUtils.getSourceContents('does/not/exist', file1.relative)).to.be.null
})

it('returns null if file does not have source map', () => {
expect(getSourceContents(file2.fullyQualifiedUrl, file1.relative)).to.be.null
expect($sourceMapUtils.getSourceContents(file2.fullyQualifiedUrl, file1.relative)).to.be.null
})
})

context('.getSourcePosition', () => {
before(() => {
return initializeSourceMapConsumer(file1, sourceMap)
return $sourceMapUtils.initializeSourceMapConsumer(file1, sourceMap)
})

it('returns source position for generated position', () => {
const position = getSourcePosition(file1.fullyQualifiedUrl, { line: 1, column: 2 })
const position = $sourceMapUtils.getSourcePosition(file1.fullyQualifiedUrl, { line: 1, column: 2 })

expect(_.pick(position, 'line', 'column')).to.eql({ line: 1, column: 0 })
})
Expand All @@ -130,14 +125,14 @@ describe('driver/src/cypress/source_map_utils', () => {
})

it('initializes and returns source map consumer and file', () => {
return initializeSourceMapConsumer(file1, sourceMap).then((consumer) => {
return $sourceMapUtils.initializeSourceMapConsumer(file1, sourceMap).then((consumer) => {
expect(SourceMapConsumer.initialize).to.be.called
expect(consumer).to.be.an.instanceof(SourceMapConsumer)
})
})

it('resolves null and does not initialize if no source map is provided', () => {
return initializeSourceMapConsumer(file1).then((consumer) => {
return $sourceMapUtils.initializeSourceMapConsumer(file1).then((consumer) => {
expect(SourceMapConsumer.initialize).not.to.be.called
expect(consumer).to.be.null
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const $stackUtils = require('@packages/driver/src/cypress/stack_utils')
const $sourceMapUtils = require('@packages/driver/src/cypress/source_map_utils')
const $stackUtils = require('@packages/driver/src/cypress/stack_utils').default
const $sourceMapUtils = require('@packages/driver/src/cypress/source_map_utils').default
const { stripIndent } = require('common-tags')

describe('driver/src/cypress/stack_utils', () => {
Expand Down
5 changes: 3 additions & 2 deletions packages/driver/cypress/integration/cypress/utils_spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const LimitedMap = require('@packages/driver/src/util/limited_map')
const LimitedMap = require('@packages/driver/src/util/limited_map').default
const { encodeBase64Unicode } = Cypress.utils
const $utils = Cypress.utils

describe('driver/src/cypress/utils', () => {
Expand Down Expand Up @@ -221,7 +222,7 @@ describe('driver/src/cypress/utils', () => {
context('.encodeBase64Unicode', () => {
it('encodes base64, with utf-8 handling', () => {
const str = 'サイプリスは一番'
const encoded = $utils.encodeBase64Unicode(str)
const encoded = encodeBase64Unicode(str)

expect(encoded).to.equal('44K144Kk44OX44Oq44K544Gv5LiA55Wq')
})
Expand Down
8 changes: 3 additions & 5 deletions packages/driver/cypress/integration/dom/elements_spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { getActiveElByDocument, isFocused, elementFromPoint } from '../../../src/dom/elements'

const { $ } = Cypress

export {}
import $elements from '../../../src/dom/elements'
const { getActiveElByDocument, isFocused, elementFromPoint } = $elements
const $ = window.Cypress.$

describe('src/dom/elements', () => {
context('.isAttached', () => {
Expand Down
2 changes: 0 additions & 2 deletions packages/driver/cypress/integration/dom/visibility_spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
const { $, dom } = Cypress

export {}

describe('src/cypress/dom/visibility', () => {
beforeEach(() => {
cy.visit('/fixtures/generic.html')
Expand Down
4 changes: 3 additions & 1 deletion packages/driver/cypress/integration/e2e/dom_hitbox.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ const ensureCorrectHighlightPositions = (sel) => {
border: cy.$$('div[data-layer=Border]'),
}

const dims = _.mapValues(els, ($el) => $el[0].getBoundingClientRect())
const dims = _.mapValues(els, ($el) => {
return $el[0].getBoundingClientRect()
})

const doc = els.content[0].ownerDocument

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const LimitedMap = require('@packages/driver/src/util/limited_map')
const LimitedMap = require('@packages/driver/src/util/limited_map').default

const _ = Cypress._

Expand Down
4 changes: 2 additions & 2 deletions packages/driver/cypress/integration/util/queue_spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import Bluebird from 'bluebird'

import { create } from '../../../src/util/queue'
import $Queue from '../../../src/util/queue'

const ids = (queueables) => queueables.map((q) => q.id)

describe('src/util/queue', () => {
let queue

beforeEach(() => {
queue = create([
queue = $Queue.create([
{ id: '1' },
{ id: '2' },
{ id: '3' },
Expand Down
16 changes: 16 additions & 0 deletions packages/driver/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>Cypress Driver</title>
</head>

<body>
This is the site for the Cypress Driver library
<script type="module" src="./index.ts"></script>
</body>

</html>
1 change: 0 additions & 1 deletion packages/driver/index.js

This file was deleted.

5 changes: 5 additions & 0 deletions packages/driver/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import $Cypress from './src/main'

export default $Cypress

export * from './src/main'
4 changes: 3 additions & 1 deletion packages/driver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@packages/runner": "0.0.0-development",
"@packages/server": "0.0.0-development",
"@packages/ts": "0.0.0-development",
"@rollup/plugin-node-resolve": "^13.0.4",
"@sinonjs/fake-timers": "7.0.2",
"@types/chalk": "^2.2.0",
"@types/common-tags": "^1.8.0",
Expand Down Expand Up @@ -51,7 +52,6 @@
"is-valid-domain": "0.0.20",
"is-valid-hostname": "1.0.1",
"jquery": "3.1.1",
"jquery.scrollto": "2.1.3",
"js-cookie": "2.2.1",
"jsdom": "14.1.0",
"json-stable-stringify": "1.0.1",
Expand All @@ -69,6 +69,7 @@
"react-16.0.0": "npm:react@16.0.0",
"react-dom-15.6.1": "npm:react-dom@15.6.1",
"react-dom-16.0.0": "npm:react-dom@16.0.0",
"rollup-plugin-node-builtins": "^2.1.2",
"setimmediate": "1.0.5",
"sinon": "8.1.1",
"source-map": "0.8.0-beta.0",
Expand All @@ -77,6 +78,7 @@
"unfetch": "4.1.0",
"url-parse": "1.5.2",
"vanilla-text-mask": "5.1.1",
"vite": "^2.4.4",
"webpack": "4.41.2",
"zone.js": "0.9.0"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const Promise = require('bluebird')
import Promise from 'bluebird'

Promise.config({
cancellation: true,
Expand Down
Loading

3 comments on commit e216ae2

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on e216ae2 Sep 7, 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/8.4.0/circle-develop-e216ae2422706d4f46e6dfa68abe2d589c72cf96/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on e216ae2 Sep 7, 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/8.4.0/appveyor-develop-e216ae2422706d4f46e6dfa68abe2d589c72cf96/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on e216ae2 Sep 7, 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/8.4.0/appveyor-develop-e216ae2422706d4f46e6dfa68abe2d589c72cf96/cypress.tgz

Please sign in to comment.