Skip to content
Open
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
10 changes: 6 additions & 4 deletions .circleci/src/pipeline/@pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,15 @@ commands:
description: Save entire folder as artifact for other jobs to run without reinstalling
steps:
- run:
name: Sync Cloud Validations
name: Build packages
command: |
source ./scripts/ensure-node.sh
yarn gulp syncCloudValidations
yarn build
- run:
name: Build packages
name: Sync Cloud Validations
command: |
source ./scripts/ensure-node.sh
yarn build
yarn gulp syncCloudValidations
- run:
name: Generate v8 snapshot
command: |
Expand Down Expand Up @@ -1234,6 +1234,8 @@ commands:
name: Check if binary exists, exit if it does
command: |
source ./scripts/ensure-node.sh
yarn workspace @packages/network-tools build
yarn workspace @packages/network build
yarn gulp e2eTestScaffold
yarn check-binary-on-cdn --version $(node ./scripts/get-next-version.js) --type binary --file cypress.zip

Expand Down
4 changes: 3 additions & 1 deletion guides/esm-migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ When migrating some of these projects away from the `ts-node` entry [see `@packa
- [x] packages/launcher ✅ **COMPLETED**
- [x] packages/launchpad ✅ **COMPLETED**
- [x] packages/net-stubbing ✅ **COMPLETED**
- [ ] packages/network **PARTIAL** - entry point is JS
- [x] packages/network ✅ **COMPLETED**
- [x] packages/network-tools ✅ **COMPLETED**
- [x] packages/packherd-require ✅ **COMPLETED**
- [ ] packages/proxy **PARTIAL** - entry point is JS
- [x] packages/reporter ✅ **COMPLETED**
Expand Down Expand Up @@ -103,6 +104,7 @@ When migrating some of these projects away from the `ts-node` entry [see `@packa
- [ ] packages/launcher
- [ ] packages/net-stubbing
- [x] packages/network ✅ **COMPLETED**
- [x] packages/network-tools ✅ **COMPLETED**
- [ ] packages/packherd-require
- [ ] packages/proxy
- [x] packages/rewriter ✅ **COMPLETED**
Expand Down
3 changes: 2 additions & 1 deletion packages/config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@
},
"devDependencies": {
"@packages/errors": "0.0.0-development",
"@packages/network": "0.0.0-development",
"@packages/network-tools": "0.0.0-development",
"@packages/root": "0.0.0-development",
"@packages/ts": "0.0.0-development",
"@packages/types": "0.0.0-development",
"babel-plugin-tester": "^10.1.0",
"rimraf": "6.0.1",
"typescript": "~5.4.5",
"vitest": "^3.2.4"
},
"files": [
Expand Down
4 changes: 2 additions & 2 deletions packages/config/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import _ from 'lodash'
import { toBoolean } from 'underscore.string'
import * as uri from '@packages/network/lib/uri'
import { origin } from '@packages/network-tools'

export const hideKeys = (token?: string | number | boolean) => {
if (!token) {
Expand All @@ -26,7 +26,7 @@ export function setUrls (obj: any) {
const proxyUrl = `http://localhost:${obj.port}`

const rootUrl = obj.baseUrl
? uri.origin(obj.baseUrl)
? origin(obj.baseUrl)
: proxyUrl

return {
Expand Down
2 changes: 1 addition & 1 deletion packages/driver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@packages/config": "0.0.0-development",
"@packages/errors": "0.0.0-development",
"@packages/net-stubbing": "0.0.0-development",
"@packages/network": "0.0.0-development",
"@packages/network-tools": "0.0.0-development",
"@packages/proxy": "0.0.0-development",
"@packages/rewriter": "0.0.0-development",
"@packages/runner": "0.0.0-development",
Expand Down
5 changes: 2 additions & 3 deletions packages/driver/src/cy/commands/origin/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import $utils from '../../../cypress/utils'
import $errUtils from '../../../cypress/error_utils'
import { difference, isPlainObject, isString, isFunction } from 'lodash'
import type { LocationObject } from '../../../cypress/location'
import * as cors from '@packages/network/lib/cors'
import { DocumentDomainInjection } from '@packages/network/lib/document-domain-injection'
import { policyFromConfig, DocumentDomainInjection } from '@packages/network-tools'

const validOptionKeys = Object.freeze(['args'])

Expand Down Expand Up @@ -87,7 +86,7 @@ export class Validator {

const injector = DocumentDomainInjection.InjectionBehavior(Cypress.config())

const policy = cors.policyFromConfig({ injectDocumentDomain: Cypress.config('injectDocumentDomain') })
const policy = policyFromConfig({ injectDocumentDomain: Cypress.config('injectDocumentDomain') })

if (injector.urlsMatch(originLocation.href, specHref)) {
$errUtils.throwErrByPath('origin.invalid_url_argument_same_origin', {
Expand Down
2 changes: 1 addition & 1 deletion packages/driver/src/cypress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import { PrimaryOriginCommunicator, SpecBridgeCommunicator } from './cross-origi
import { setupAutEventHandlers } from './cypress/aut_event_handlers'

import type { CachedTestState, ReporterRunState, RunState } from '@packages/types'
import { DocumentDomainInjection } from '@packages/network/lib/document-domain-injection'
import { DocumentDomainInjection } from '@packages/network-tools'
import { setSpecContentSecurityPolicy } from './util/privileged_channel'

import { telemetry } from '@packages/telemetry/src/browser'
Expand Down
6 changes: 3 additions & 3 deletions packages/driver/src/cypress/location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import _ from 'lodash'
import UrlParse from 'url-parse'
import * as cors from '@packages/network/lib/cors'
import { getSuperDomain, getSuperDomainOrigin } from '@packages/network-tools'

const reHttp = /^https?:\/\//
const reWww = /^www/
Expand Down Expand Up @@ -106,11 +106,11 @@ export class $Location {
}

getSuperDomainOrigin () {
return cors.getSuperDomainOrigin(this.remote.href)
return getSuperDomainOrigin(this.remote.href)
}

getSuperDomain () {
return cors.getSuperDomain(this.remote.href)
return getSuperDomain(this.remote.href)
}

getToString () {
Expand Down
1 change: 1 addition & 0 deletions packages/network-tools/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/tsconfig.json
2 changes: 2 additions & 0 deletions packages/network-tools/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cjs/
esm/
33 changes: 33 additions & 0 deletions packages/network-tools/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# network-tools

A low-level package that contains networking-related classes and utilities to be used in the browser and Node.js environment.

## Exports

You can see a list of the modules exported from this package in [./lib/index.ts](./lib/index.ts). Here is a brief description of what's available:

* `cors` contains utilities for Cross-Origin Resource Sharing
* `document-domain-injection` contains utilities related to document.domain injection of the Cypress driver
* `uri` contains utilities for URL parsing and formatting

See the individual class files in [`./lib`](./lib) for more information.

## Building

We currently build a CommonJS and an ESM version of this package. However, since this package is only consumed via CommonJS, we currently only build the CommonJS variant of the package.

```shell
yarn workspace @packages/network-tools build-prod
```

## Testing

Tests are located in [`./test`](./test)

To run tests:

```shell
yarn workspace @packages/network-tools test
yarn workspace @packages/network-tools test-watch
yarn workspace @packages/network-tools test-debug
```
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import _ from 'lodash'
import * as uri from './uri'
import { addDefaultPort, parse as parseUrl } from './uri'
import debugModule from 'debug'
import _parseDomain from '@cypress/parse-domain'
import type { ParsedHost, ParsedHostWithProtocolAndHost } from './types'
Expand All @@ -25,7 +25,7 @@ export function parseDomain (domain: string, options = {}) {
}

export function parseUrlIntoHostProtocolDomainTldPort (str: string) {
let { hostname, port, protocol } = uri.parse(str)
let { hostname, port, protocol } = parseUrl(str)

if (!hostname) {
hostname = ''
Expand Down Expand Up @@ -200,9 +200,9 @@ declare module 'url' {
}
}

export function urlMatchesOriginProtectionSpace (urlStr, origin) {
const normalizedUrl = uri.addDefaultPort(urlStr).format()
const normalizedOrigin = uri.addDefaultPort(origin).format()
export function urlMatchesOriginProtectionSpace (urlStr: string, origin: string) {
const normalizedUrl = addDefaultPort(urlStr).format()
const normalizedOrigin = addDefaultPort(origin).format()

return _.startsWith(normalizedUrl, normalizedOrigin)
}
Expand Down
7 changes: 7 additions & 0 deletions packages/network-tools/lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export * from './cors'

export * from './uri'

export * from './types'

export * from './document-domain-injection'
File renamed without changes.
File renamed without changes.
39 changes: 39 additions & 0 deletions packages/network-tools/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "@packages/network-tools",
"version": "0.0.0-development",
"private": true,
"main": "cjs/index.js",
"scripts": {
"build": "yarn build:esm && yarn build:cjs",
"build-prod": "yarn build",
"build:cjs": "rimraf cjs && tsc -p tsconfig.cjs.json",
"build:esm": "rimraf esm && tsc -p tsconfig.esm.json",
"check-ts": "tsc -p tsconfig.cjs.json --noEmit && yarn -s tslint -p tsconfig.cjs.json",
"clean": "rimraf cjs esm",
"clean-deps": "rimraf node_modules",
"lint": "eslint --ext .js,.jsx,.ts,.tsx,.json, .",
"test": "yarn test-unit",
"test-debug": "npx vitest --inspect-brk --no-file-parallelism --test-timeout=0 --hook-timeout=0",
"test-unit": "vitest run",
"test-watch": "yarn test-unit --watch",
"tslint": "tslint --config ../ts/tslint.json --project .",
"watch": "tsc -p tsconfig.cjs.json --watch"
},
"dependencies": {
"@cypress/parse-domain": "2.4.0",
"debug": "^4.3.4",
"lodash": "^4.17.21"
},
"devDependencies": {
"rimraf": "6.0.1",
"typescript": "~5.4.5",
"vitest": "^3.2.4"
},
"files": [
"cjs",
"esm"
],
"types": "./cjs/index.d.ts",
"module": "esm/index.js",
"nx": {}
}
Loading
Loading