mirror of
https://github.com/cypress-io/cypress.git
synced 2026-01-30 19:18:45 -06:00
chore: convert @packages/net-stubbing tests to vitest from mocha (#32758)
This commit is contained in:
@@ -1785,7 +1785,7 @@ jobs:
|
||||
source ./scripts/ensure-node.sh
|
||||
yarn lerna run types
|
||||
- sanitize-verify-and-store-mocha-results:
|
||||
expectedResultCount: 7
|
||||
expectedResultCount: 6
|
||||
|
||||
verify-release-readiness:
|
||||
<<: *defaults
|
||||
|
||||
@@ -100,7 +100,7 @@ When migrating some of these projects away from the `ts-node` entry [see `@packa
|
||||
- [x] packages/electron ✅ **COMPLETED**
|
||||
- [x] packages/icons ✅ **COMPLETED**
|
||||
- [x] packages/launcher ✅ **COMPLETED**
|
||||
- [ ] packages/net-stubbing
|
||||
- [x] packages/net-stubbing ✅ **COMPLETED**
|
||||
- [x] packages/network ✅ **COMPLETED**
|
||||
- [x] packages/network-tools ✅ **COMPLETED**
|
||||
- [ ] packages/packherd-require
|
||||
|
||||
@@ -8,7 +8,9 @@
|
||||
"check-ts": "tsc --noEmit && yarn -s tslint",
|
||||
"clean-deps": "rimraf node_modules",
|
||||
"lint": "eslint --ext .ts,.json, .",
|
||||
"test": "CYPRESS_INTERNAL_ENV=test mocha -r @packages/ts/register --reporter mocha-multi-reporters --reporter-options configFile=../../mocha-reporter-config.json --exit test/unit/*",
|
||||
"test": "vitest",
|
||||
"test-debug": "vitest --inspect-brk --no-file-parallelism --test-timeout=0",
|
||||
"test-watch": "vitest watch",
|
||||
"tslint": "tslint --config ../ts/tslint.json --project ."
|
||||
},
|
||||
"dependencies": {
|
||||
@@ -26,8 +28,7 @@
|
||||
"@packages/server": "0.0.0-development",
|
||||
"@packages/telemetry": "0.0.0-development",
|
||||
"@types/mime": "^3.0.1",
|
||||
"chai": "4.2.0",
|
||||
"mocha": "7.1.2"
|
||||
"vitest": "^3.2.4"
|
||||
},
|
||||
"files": [
|
||||
"lib"
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import {
|
||||
_restoreMatcherOptionsTypes,
|
||||
} from '../../lib/server/driver-events'
|
||||
import { expect } from 'chai'
|
||||
|
||||
describe('driver events', function () {
|
||||
context('._restoreMatcherOptionsTypes', function () {
|
||||
describe('._restoreMatcherOptionsTypes', function () {
|
||||
it('rehydrates regexes properly', function () {
|
||||
const { url } = _restoreMatcherOptionsTypes({
|
||||
url: {
|
||||
@@ -13,8 +13,8 @@ describe('driver events', function () {
|
||||
},
|
||||
})
|
||||
|
||||
expect(url).to.be.instanceOf(RegExp)
|
||||
.and.include({
|
||||
expect(url).toBeInstanceOf(RegExp)
|
||||
expect(url).toMatchObject({
|
||||
flags: 'gim',
|
||||
source: 'aaa',
|
||||
})
|
||||
@@ -1,17 +1,13 @@
|
||||
import chai, { expect } from 'chai'
|
||||
import { describe, it, expect, vi } from 'vitest'
|
||||
import _ from 'lodash'
|
||||
import sinon from 'sinon'
|
||||
import sinonChai from 'sinon-chai'
|
||||
import { InterceptedRequest } from '../../lib/server/intercepted-request'
|
||||
import { state as NetStubbingState } from '../../lib/server/state'
|
||||
|
||||
chai.use(sinonChai)
|
||||
|
||||
describe('InterceptedRequest', () => {
|
||||
context('handleSubscriptions', () => {
|
||||
describe('handleSubscriptions', () => {
|
||||
it('handles subscriptions as expected', async () => {
|
||||
const socket = {
|
||||
toDriver: sinon.stub(),
|
||||
toDriver: vi.fn(),
|
||||
}
|
||||
const state = NetStubbingState()
|
||||
const interceptedRequest = new InterceptedRequest({
|
||||
@@ -45,10 +41,10 @@ describe('InterceptedRequest', () => {
|
||||
|
||||
const data = { foo: 'bar' }
|
||||
|
||||
socket.toDriver.callsFake((eventName, subEventName, frame) => {
|
||||
expect(eventName).to.eq('net:stubbing:event')
|
||||
expect(subEventName).to.eq('before:request')
|
||||
expect(frame).to.deep.include({
|
||||
socket.toDriver.mockImplementation((eventName, subEventName, frame) => {
|
||||
expect(eventName).toEqual('net:stubbing:event')
|
||||
expect(subEventName).toEqual('before:request')
|
||||
expect(frame).toMatchObject({
|
||||
subscription: {
|
||||
eventName: 'before:request',
|
||||
await: true,
|
||||
@@ -65,12 +61,12 @@ describe('InterceptedRequest', () => {
|
||||
mergeChanges: _.merge,
|
||||
})
|
||||
|
||||
expect(socket.toDriver).to.be.calledTwice
|
||||
expect(socket.toDriver).toHaveBeenCalledTimes(2)
|
||||
})
|
||||
|
||||
it('ignores disabled subscriptions', async () => {
|
||||
const socket = {
|
||||
toDriver: sinon.stub(),
|
||||
toDriver: vi.fn(),
|
||||
}
|
||||
const state = NetStubbingState()
|
||||
const interceptedRequest = new InterceptedRequest({
|
||||
@@ -99,10 +95,10 @@ describe('InterceptedRequest', () => {
|
||||
|
||||
const data = { foo: 'bar' }
|
||||
|
||||
socket.toDriver.callsFake((eventName, subEventName, frame) => {
|
||||
expect(eventName).to.eq('net:stubbing:event')
|
||||
expect(subEventName).to.eq('before:request')
|
||||
expect(frame).to.deep.include({
|
||||
socket.toDriver.mockImplementation((eventName, subEventName, frame) => {
|
||||
expect(eventName).toEqual('net:stubbing:event')
|
||||
expect(subEventName).toEqual('before:request')
|
||||
expect(frame).toMatchObject({
|
||||
subscription: {
|
||||
eventName: 'before:request',
|
||||
await: true,
|
||||
@@ -119,7 +115,7 @@ describe('InterceptedRequest', () => {
|
||||
mergeChanges: _.merge,
|
||||
})
|
||||
|
||||
expect(socket.toDriver).to.be.calledOnce
|
||||
expect(socket.toDriver).toHaveBeenCalledOnce()
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1,15 +1,15 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import {
|
||||
_doesRouteMatch,
|
||||
_getMatchableForRequest,
|
||||
getRoutesForRequest,
|
||||
} from '../../lib/server/route-matching'
|
||||
import { RouteMatcherOptions } from '../../lib/types'
|
||||
import { expect } from 'chai'
|
||||
import { CypressIncomingRequest } from '@packages/proxy'
|
||||
import { BackendRoute } from '../../lib/server/types'
|
||||
|
||||
describe('intercept-request', function () {
|
||||
context('._getMatchableForRequest', function () {
|
||||
describe('._getMatchableForRequest', function () {
|
||||
it('converts a fully-fledged req into a matchable shape', function () {
|
||||
const req = {
|
||||
headers: {
|
||||
@@ -23,7 +23,7 @@ describe('intercept-request', function () {
|
||||
|
||||
const matchable = _getMatchableForRequest(req)
|
||||
|
||||
expect(matchable).to.deep.eq({
|
||||
expect(matchable).toEqual({
|
||||
auth: {
|
||||
username: 'foo',
|
||||
password: 'bar',
|
||||
@@ -43,7 +43,7 @@ describe('intercept-request', function () {
|
||||
})
|
||||
})
|
||||
|
||||
context('._doesRouteMatch', function () {
|
||||
describe('._doesRouteMatch', function () {
|
||||
const tryMatch = (req: Partial<CypressIncomingRequest>, matcher: RouteMatcherOptions, expected = true) => {
|
||||
req = {
|
||||
method: 'GET',
|
||||
@@ -51,7 +51,7 @@ describe('intercept-request', function () {
|
||||
...req,
|
||||
}
|
||||
|
||||
expect(_doesRouteMatch(matcher, req as CypressIncomingRequest)).to.eq(expected)
|
||||
expect(_doesRouteMatch(matcher, req as CypressIncomingRequest)).toEqual(expected)
|
||||
}
|
||||
|
||||
it('matches exact URL', function () {
|
||||
@@ -172,7 +172,7 @@ describe('intercept-request', function () {
|
||||
})
|
||||
})
|
||||
|
||||
context('.getRoutesForRequest', function () {
|
||||
describe('.getRoutesForRequest', function () {
|
||||
it('matches middleware, then handlers', function () {
|
||||
const routes: Partial<BackendRoute>[] = [
|
||||
{
|
||||
@@ -216,7 +216,7 @@ describe('intercept-request', function () {
|
||||
e.push(route.id)
|
||||
}
|
||||
|
||||
expect(e).to.deep.eq(['1', '3', '4', '2'])
|
||||
expect(e).toEqual(['1', '3', '4', '2'])
|
||||
})
|
||||
|
||||
it('yields identical matches', function () {
|
||||
@@ -255,7 +255,7 @@ describe('intercept-request', function () {
|
||||
matchedRouteIds.push(route.id)
|
||||
}
|
||||
|
||||
expect(matchedRouteIds).to.deep.eq(['1', '1'])
|
||||
expect(matchedRouteIds).toEqual(['1', '1'])
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { getBodyEncoding, parseContentType } from '../../lib/server/util'
|
||||
import { expect } from 'chai'
|
||||
import { join } from 'path'
|
||||
import { readFileSync } from 'fs'
|
||||
|
||||
@@ -10,7 +10,7 @@ describe('net-stubbing util', () => {
|
||||
it('returns application/json', () => {
|
||||
const str = JSON.stringify({ foo: 'bar' })
|
||||
|
||||
expect(parseContentType(str)).to.eq('application/json')
|
||||
expect(parseContentType(str)).toEqual('application/json')
|
||||
})
|
||||
|
||||
it('returns text/html', () => {
|
||||
@@ -20,23 +20,23 @@ describe('net-stubbing util', () => {
|
||||
</html>\
|
||||
`
|
||||
|
||||
expect(parseContentType(str)).to.eq('text/html')
|
||||
expect(parseContentType(str)).toEqual('text/html')
|
||||
})
|
||||
|
||||
it('returns text/plain', () => {
|
||||
const str = 'foobar<p>baz'
|
||||
|
||||
expect(parseContentType(str)).to.eq('text/plain')
|
||||
expect(parseContentType(str)).toEqual('text/plain')
|
||||
})
|
||||
|
||||
it('returns text/plain by default', () => {
|
||||
expect(parseContentType()).to.eq('text/plain')
|
||||
expect(parseContentType()).toEqual('text/plain')
|
||||
})
|
||||
})
|
||||
|
||||
context('getBodyEncoding', () => {
|
||||
describe('getBodyEncoding', () => {
|
||||
it('returns null without data', () => {
|
||||
expect(getBodyEncoding(null)).to.equal(null)
|
||||
expect(getBodyEncoding(null)).toBeNull()
|
||||
|
||||
const emptyRequest = {
|
||||
body: null,
|
||||
@@ -46,7 +46,7 @@ describe('net-stubbing util', () => {
|
||||
httpVersion: '1.1',
|
||||
}
|
||||
|
||||
expect(getBodyEncoding(emptyRequest)).to.equal(null)
|
||||
expect(getBodyEncoding(emptyRequest)).toBeNull()
|
||||
})
|
||||
|
||||
it('returns utf8', () => {
|
||||
@@ -70,7 +70,7 @@ describe('net-stubbing util', () => {
|
||||
httpVersion: '1.1',
|
||||
}
|
||||
|
||||
expect(getBodyEncoding(req), contentType).to.equal('utf8')
|
||||
expect(getBodyEncoding(req), contentType).toEqual('utf8')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -83,7 +83,7 @@ describe('net-stubbing util', () => {
|
||||
httpVersion: '1.1',
|
||||
}
|
||||
|
||||
expect(getBodyEncoding(req), 'text').to.equal('utf8')
|
||||
expect(getBodyEncoding(req), 'text').toEqual('utf8')
|
||||
})
|
||||
|
||||
it('falls back to inspecting bytes to find image', () => {
|
||||
@@ -95,7 +95,7 @@ describe('net-stubbing util', () => {
|
||||
httpVersion: '1.1',
|
||||
}
|
||||
|
||||
expect(getBodyEncoding(req), 'image').to.equal('binary')
|
||||
expect(getBodyEncoding(req), 'image').toEqual('binary')
|
||||
})
|
||||
})
|
||||
})
|
||||
12
packages/net-stubbing/vitest.config.ts
Normal file
12
packages/net-stubbing/vitest.config.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { defineConfig } from 'vitest/config'
|
||||
|
||||
export default defineConfig({
|
||||
test: {
|
||||
env: {
|
||||
CYPRESS_INTERNAL_ENV: 'test',
|
||||
},
|
||||
include: ['test/**/*.spec.ts'],
|
||||
globals: true,
|
||||
environment: 'node',
|
||||
},
|
||||
})
|
||||
30
yarn.lock
30
yarn.lock
@@ -23966,36 +23966,6 @@ mocha@7.1.0:
|
||||
yargs-parser "13.1.1"
|
||||
yargs-unparser "1.6.0"
|
||||
|
||||
mocha@7.1.2:
|
||||
version "7.1.2"
|
||||
resolved "https://registry.yarnpkg.com/mocha/-/mocha-7.1.2.tgz#8e40d198acf91a52ace122cd7599c9ab857b29e6"
|
||||
integrity sha512-o96kdRKMKI3E8U0bjnfqW4QMk12MwZ4mhdBTf+B5a1q9+aq2HRnj+3ZdJu0B/ZhJeK78MgYuv6L8d/rA5AeBJA==
|
||||
dependencies:
|
||||
ansi-colors "3.2.3"
|
||||
browser-stdout "1.3.1"
|
||||
chokidar "3.3.0"
|
||||
debug "3.2.6"
|
||||
diff "3.5.0"
|
||||
escape-string-regexp "1.0.5"
|
||||
find-up "3.0.0"
|
||||
glob "7.1.3"
|
||||
growl "1.10.5"
|
||||
he "1.2.0"
|
||||
js-yaml "3.13.1"
|
||||
log-symbols "3.0.0"
|
||||
minimatch "3.0.4"
|
||||
mkdirp "0.5.5"
|
||||
ms "2.1.1"
|
||||
node-environment-flags "1.0.6"
|
||||
object.assign "4.1.0"
|
||||
strip-json-comments "2.0.1"
|
||||
supports-color "6.0.0"
|
||||
which "1.3.1"
|
||||
wide-align "1.1.3"
|
||||
yargs "13.3.2"
|
||||
yargs-parser "13.1.2"
|
||||
yargs-unparser "1.6.0"
|
||||
|
||||
mocha@7.2.0, mocha@^7.1.0:
|
||||
version "7.2.0"
|
||||
resolved "https://registry.yarnpkg.com/mocha/-/mocha-7.2.0.tgz#01cc227b00d875ab1eed03a75106689cfed5a604"
|
||||
|
||||
Reference in New Issue
Block a user