Skip to content

Commit

Permalink
Enhance test reliability by using node:assert (#4350)
Browse files Browse the repository at this point in the history
  • Loading branch information
gcanti authored Jan 30, 2025
1 parent bb05fb8 commit 6f1c3d7
Show file tree
Hide file tree
Showing 382 changed files with 10,605 additions and 10,405 deletions.
13 changes: 6 additions & 7 deletions packages/effect/src/Chunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,8 @@ export const empty: <A = never>() => Chunk<A> = () => _empty
* @category constructors
* @since 2.0.0
*/
export const make = <As extends readonly [any, ...ReadonlyArray<any>]>(
...as: As
): NonEmptyChunk<As[number]> => as.length === 1 ? of(as[0]) : unsafeFromNonEmptyArray(as)
export const make = <As extends readonly [any, ...ReadonlyArray<any>]>(...as: As): NonEmptyChunk<As[number]> =>
unsafeFromNonEmptyArray(as)

/**
* Builds a `NonEmptyChunk` from a single element.
Expand All @@ -249,7 +248,7 @@ export const of = <A>(a: A): NonEmptyChunk<A> => makeChunk({ _tag: "ISingleton",
* @since 2.0.0
*/
export const fromIterable = <A>(self: Iterable<A>): Chunk<A> =>
isChunk(self) ? self : makeChunk({ _tag: "IArray", array: RA.fromIterable(self) })
isChunk(self) ? self : unsafeFromArray(RA.fromIterable(self))

const copyToArray = <A>(self: Chunk<A>, array: Array<any>, initial: number): void => {
switch (self.backing._tag) {
Expand Down Expand Up @@ -384,7 +383,8 @@ export const get: {
* @since 2.0.0
* @category unsafe
*/
export const unsafeFromArray = <A>(self: ReadonlyArray<A>): Chunk<A> => makeChunk({ _tag: "IArray", array: self })
export const unsafeFromArray = <A>(self: ReadonlyArray<A>): Chunk<A> =>
self.length === 0 ? empty() : self.length === 1 ? of(self[0]) : makeChunk({ _tag: "IArray", array: self })

/**
* Wraps an array into a chunk without copying, unsafe on mutable arrays
Expand Down Expand Up @@ -1216,8 +1216,7 @@ export const zip: {
)

/**
* Delete the element at the specified index, creating a new `Chunk`,
* or returning the input if the index is out of bounds.
* Delete the element at the specified index, creating a new `Chunk`.
*
* @since 2.0.0
*/
Expand Down
1 change: 1 addition & 0 deletions packages/effect/src/ConfigProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ export const fromFlat: (flat: ConfigProvider.Flat) => ConfigProvider = internal.
*/
export const fromJson: (json: unknown) => ConfigProvider = internal.fromJson

// TODO: use `_` for nested configs instead of `.` in next major
/**
* Constructs a ConfigProvider using a map and the specified delimiter string,
* which determines how to split the keys in the map into path segments.
Expand Down
23 changes: 15 additions & 8 deletions packages/effect/src/ParseResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

import * as array_ from "./Array.js"
import type * as cause_ from "./Cause.js"
import * as cause_ from "./Cause.js"
import { TaggedError } from "./Data.js"
import * as Effect from "./Effect.js"
import * as Either from "./Either.js"
Expand All @@ -14,6 +14,7 @@ import * as Inspectable from "./Inspectable.js"
import * as util_ from "./internal/schema/util.js"
import * as Option from "./Option.js"
import * as Predicate from "./Predicate.js"
import * as Runtime from "./Runtime.js"
import type * as Schema from "./Schema.js"
import * as AST from "./SchemaAST.js"
import type { Concurrency } from "./Types.js"
Expand Down Expand Up @@ -1649,13 +1650,19 @@ const handleForbidden = <A, R>(
try {
return Effect.runSync(Effect.either(effect as Effect.Effect<A, ParseIssue>))
} catch (e) {
return Either.left(
new Forbidden(
ast,
actual,
"cannot be be resolved synchronously, this is caused by using runSync on an effect that performs async work"
)
)
if (Runtime.isFiberFailure(e)) {
const cause = e[Runtime.FiberFailureCauseId]
if (cause_.isDieType(cause) && Runtime.isAsyncFiberException(cause.defect)) {
return Either.left(
new Forbidden(
ast,
actual,
"cannot be be resolved synchronously, this is caused by using runSync on an effect that performs async work"
)
)
}
}
return Either.left(new Forbidden(ast, actual, String(e)))
}
}

Expand Down
10 changes: 6 additions & 4 deletions packages/effect/src/internal/secret.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@ export const SecretTypeId: Secret.SecretTypeId = Symbol.for(
*/
export const isSecret = (u: unknown): u is Secret.Secret => hasProperty(u, SecretTypeId)

const SecretProto = {
...redacted_.proto,
[SecretTypeId]: SecretTypeId
}

/**
* @internal
* @deprecated
*/
export const make = (bytes: Array<number>): Secret.Secret => {
const secret = Object.create({
...redacted_.proto,
[SecretTypeId]: SecretTypeId
})
const secret = Object.create(SecretProto)
Object.defineProperty(secret, "toString", {
enumerable: false,
value() {
Expand Down
Loading

0 comments on commit 6f1c3d7

Please sign in to comment.