mirror of
https://github.com/cypress-io/cypress.git
synced 2026-01-14 10:59:54 -06:00
* Initial async changes * Small fixes and test updates. * updating tests * Fixes for cookie login tests * remove the onlys * Most tests passing * Fix driver tests? * fix firefox test? * fix unit tests * fix tests?? * a better check * fix integration tests * minor cleanup * Comment out tyler fix for 10.0 origin issue * also fix integration tests * remove fixmes * Adding Retries for cookie actions. May break other error tests. * Address (some) PR comments * factor console logging out of run.ts * fix print-run * minimize diff * chore(server): convert browsers/index to typescript * fix tests * update stubbed tests * convert electron.js to .ts * Suggestions from code review * Clean up new type errors * electron.connectToExisting can be sync * more type errors for the type god * Suggestions from code review * refactor: move more of video capture into browser automations * unit tests * refactor: move videoCapture to browsers * fix snapshots * update to warn about cross origin command AUT in assertions * Fix type errors * fix multi-spec videos? * webkit video recording works! * webkit system tests * skip system-tests that won't be fixed in this PR ~60 tests skipped out of ~99: * ~6 skipped due to needing multidomain support * ~8 skipped due to missing before:browser:launch support * ~22 skipped due to broken stack traces * fix single-tab mode * cleanup/api renames * fix more tests * minimize diff, fix ff * fix unit tests * fix tests * cleanup * Move document.cookie patch to injection * enable ci job * fix up/add request events to webkit automation * update undefined message * doesn't need an underscore * Adding iframe patching. * forward errors prior to attaching * Add error message when using visit to visit a cross origin site with the onLoad or onBeforeLoad options. * Attempt to fix test errors. * more fixes, but not all * use the origin policy * Fix types * more fixes * consider chromeWebSecurity when checking if you can communicate with the AUT * firefox * prevent hangs if before unload happens after on load. * Fix some ToDos * code cleanup * remove quotes * Code review changes * more cr changes * fix tests possibly * Updating cy.origin websocket for webkit connection error * for realz this time * temp fix for before:unload/load issue * roll back change * Fix some flake * temporarily comment out autWindow.Error patch * updating cookies to match develop * update circle.yml * commenting out driver-integration-tests-webkit-experimentalSessionAndOrigin * revert cookie test change * revert cross origin change * Fix clear cookie problem * Try it again * test cy.origin in webkit * Skip origin tests when running in webkit * missed one * attempt to revert web_security changes * enable sessions on webkit * maybe this fixes system tests?? * Update web_security_spec.js * Update web_security_spec.js * file cleanup * Unify socket creation logic * Address PR Comments Co-authored-by: mjhenkes <mjhenkes@gmail.com> Co-authored-by: Matt Schile <mschile@cypress.io>
242 lines
6.2 KiB
JavaScript
242 lines
6.2 KiB
JavaScript
const fs = require('fs')
|
|
const path = require('path')
|
|
const server = require('socket.io')
|
|
const client = require('socket.io-client')
|
|
const parser = require('socket.io-parser')
|
|
const { hasBinary } = require('socket.io-parser/dist/is-binary')
|
|
const expect = require('chai').expect
|
|
const pkg = require('../package.json')
|
|
const lib = require('../index')
|
|
const browserLib = require('../lib/browser')
|
|
const resolvePkg = require('resolve-pkg')
|
|
|
|
const { PacketType } = parser
|
|
|
|
describe('Socket', function () {
|
|
it('exports server', function () {
|
|
expect(lib.server).to.eq(server)
|
|
})
|
|
|
|
it('exports client from lib/browser', function () {
|
|
expect(browserLib.client).to.eq(client)
|
|
})
|
|
|
|
it('exports createWebSocket from lib/browser', function () {
|
|
expect(browserLib.createWebsocket).to.be.defined
|
|
})
|
|
|
|
it('creates a websocket for non webkit browsers', function () {
|
|
const socket = browserLib.createWebsocket({ path: '/path', browserFamily: 'chromium' })
|
|
|
|
expect(socket.io.opts.path).to.eq('/path')
|
|
expect(socket.io.opts.transports[0]).to.eq('websocket')
|
|
})
|
|
|
|
it('creates a websocket for non webkit browsers', function () {
|
|
const socket = browserLib.createWebsocket({ path: '/path', browserFamily: 'webkit' })
|
|
|
|
expect(socket.io.opts.path).to.eq('/path')
|
|
expect(socket.io.opts.transports[0]).to.eq('polling')
|
|
})
|
|
|
|
context('.getPathToClientSource', function () {
|
|
it('returns path to socket.io.js', function () {
|
|
const clientPath = path.join(resolvePkg('socket.io-client'), 'dist', 'socket.io.js')
|
|
|
|
expect(lib.getPathToClientSource()).to.eq(clientPath)
|
|
})
|
|
|
|
it('makes sure socket.io.js actually exists', function (done) {
|
|
fs.stat(lib.getPathToClientSource(), done)
|
|
})
|
|
})
|
|
|
|
context('.getClientVersion', function () {
|
|
it('returns client version', function () {
|
|
expect(lib.getClientVersion()).to.eq(pkg.dependencies['socket.io-client'])
|
|
})
|
|
})
|
|
|
|
context('blob encoding + decoding', () => {
|
|
it('correctly encodes and decodes binary blob data', (done) => {
|
|
const encoder = new parser.Encoder()
|
|
|
|
const obj = {
|
|
type: PacketType.EVENT,
|
|
data: ['a', Buffer.from('abc', 'utf8')],
|
|
// data: ['a', { foo: 'bar' }],
|
|
id: 23,
|
|
nsp: '/cool',
|
|
}
|
|
|
|
const originalData = obj.data
|
|
|
|
const encodedPackets = encoder.encode(obj)
|
|
|
|
const decoder = new parser.Decoder()
|
|
|
|
decoder.on('decoded', (packet) => {
|
|
obj.data = originalData
|
|
obj.attachments = undefined
|
|
expect(packet).to.eql(obj)
|
|
done()
|
|
})
|
|
|
|
for (let i = 0; i < encodedPackets.length; i++) {
|
|
decoder.add(encodedPackets[i])
|
|
}
|
|
})
|
|
|
|
it('correctly encodes and decodes circular data', (done) => {
|
|
const encoder = new parser.Encoder()
|
|
|
|
const circularObj = {
|
|
foo: {},
|
|
}
|
|
|
|
circularObj.foo.circularObj = circularObj
|
|
|
|
const obj = {
|
|
type: PacketType.EVENT,
|
|
data: ['a', circularObj],
|
|
id: 23,
|
|
nsp: '/cool',
|
|
}
|
|
|
|
const originalData = obj.data
|
|
|
|
const encodedPackets = encoder.encode(obj)
|
|
|
|
const decoder = new parser.Decoder()
|
|
|
|
decoder.on('decoded', (packet) => {
|
|
obj.data = originalData
|
|
expect(packet.data[1] === packet.data[1].foo.circularObj).to.be.true
|
|
expect(packet).to.eql(obj)
|
|
done()
|
|
})
|
|
|
|
for (let i = 0; i < encodedPackets.length; i++) {
|
|
decoder.add(encodedPackets[i])
|
|
}
|
|
})
|
|
|
|
it('correctly encodes and decodes circular data in array', (done) => {
|
|
const encoder = new parser.Encoder()
|
|
|
|
const circularObj = {
|
|
foo: {},
|
|
}
|
|
|
|
circularObj.foo.circularArray = [circularObj, circularObj]
|
|
|
|
const obj = {
|
|
type: PacketType.EVENT,
|
|
data: ['a', circularObj],
|
|
id: 23,
|
|
nsp: '/cool',
|
|
}
|
|
|
|
const originalData = obj.data
|
|
|
|
const encodedPackets = encoder.encode(obj)
|
|
|
|
const decoder = new parser.Decoder()
|
|
|
|
decoder.on('decoded', (packet) => {
|
|
obj.data = originalData
|
|
expect(packet.data[1] === packet.data[1].foo.circularArray[0]).to.be.true
|
|
expect(packet.data[1] === packet.data[1].foo.circularArray[1]).to.be.true
|
|
expect(packet).to.eql(obj)
|
|
done()
|
|
})
|
|
|
|
for (let i = 0; i < encodedPackets.length; i++) {
|
|
decoder.add(encodedPackets[i])
|
|
}
|
|
})
|
|
|
|
it('correctly encodes and decodes circular data containing binary', (done) => {
|
|
const encoder = new parser.Encoder()
|
|
|
|
const circularObj = {
|
|
foo: {},
|
|
bin: Buffer.from('abc', 'utf8'),
|
|
}
|
|
|
|
circularObj.foo.circularObj = circularObj
|
|
|
|
const obj = {
|
|
type: PacketType.EVENT,
|
|
data: ['a', circularObj],
|
|
id: 23,
|
|
nsp: '/cool',
|
|
}
|
|
|
|
const originalData = obj.data
|
|
|
|
const encodedPackets = encoder.encode(obj)
|
|
|
|
const decoder = new parser.Decoder()
|
|
|
|
decoder.on('decoded', (packet) => {
|
|
obj.data = originalData
|
|
obj.attachments = undefined
|
|
expect(packet.data[1] === packet.data[1].foo.circularObj).to.be.true
|
|
expect(packet).to.eql(obj)
|
|
done()
|
|
})
|
|
|
|
for (let i = 0; i < encodedPackets.length; i++) {
|
|
decoder.add(encodedPackets[i])
|
|
}
|
|
})
|
|
|
|
it('correctly encodes and decodes binary data with objs with no prototype', (done) => {
|
|
const encoder = new parser.Encoder()
|
|
|
|
const noProtoObj = Object.create(null)
|
|
|
|
noProtoObj.foo = 'foo'
|
|
|
|
const obj = {
|
|
type: PacketType.EVENT,
|
|
data: ['a', noProtoObj, Buffer.from('123', 'utf8')],
|
|
id: 23,
|
|
nsp: '/cool',
|
|
}
|
|
|
|
const originalData = obj.data
|
|
|
|
const encodedPackets = encoder.encode(obj)
|
|
|
|
const decoder = new parser.Decoder()
|
|
|
|
decoder.on('decoded', (packet) => {
|
|
obj.data = originalData
|
|
obj.attachments = undefined
|
|
expect(packet).to.eql(obj)
|
|
done()
|
|
})
|
|
|
|
for (let i = 0; i < encodedPackets.length; i++) {
|
|
decoder.add(encodedPackets[i])
|
|
}
|
|
})
|
|
})
|
|
|
|
context('hasBinary', () => {
|
|
it('hasBinary handles binary data in toJSON()', () => {
|
|
const x = {
|
|
toJSON () {
|
|
return Buffer.from('123', 'utf8')
|
|
},
|
|
}
|
|
|
|
const data = ['a', x]
|
|
|
|
expect(hasBinary(data)).to.be.true
|
|
})
|
|
})
|
|
})
|