Socket
Socket
Sign inDemoInstall

@serenity-js/core

Package Overview
Dependencies
Maintainers
1
Versions
371
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@serenity-js/core - npm Package Compare versions

Comparing version 3.14.2 to 3.15.0

18

CHANGELOG.md

@@ -6,2 +6,20 @@ # Change Log

# [3.15.0](https://github.com/serenity-js/serenity-js/compare/v3.14.2...v3.15.0) (2024-01-12)
### Bug Fixes
* **deps:** update dependency moment to v2.30.1 ([42ec5c3](https://github.com/serenity-js/serenity-js/commit/42ec5c3b0052a0f939eec761a06ad83c632c7eb8))
### Features
* **core:** enabled ClassLoader to instantiate StageCrewMembers using their factory functions ([f98bd42](https://github.com/serenity-js/serenity-js/commit/f98bd4206e768d5840d6e7952c61f7a2da1b144e)), closes [#1147](https://github.com/serenity-js/serenity-js/issues/1147)
* **core:** timestamps can be represented as ISO8601-compatible strings ([b19e064](https://github.com/serenity-js/serenity-js/commit/b19e064abdbf5073bc701dd238098aa31ba7fc5a))
* **serenity-bdd:** support for Serenity BDD 4 ([c15c366](https://github.com/serenity-js/serenity-js/commit/c15c3660f957c21c367f8f27218a05d3fbca78de)), closes [#1147](https://github.com/serenity-js/serenity-js/issues/1147)
## [3.14.2](https://github.com/serenity-js/serenity-js/compare/v3.14.1...v3.14.2) (2023-12-12)

@@ -8,0 +26,0 @@

1

lib/io/FileSystem.d.ts

@@ -14,2 +14,3 @@ /// <reference types="node" />

constructor(root: Path, fs?: typeof nodeFS, os?: typeof nodeOS, directoryMode?: number);
resolve(relativeOrAbsolutePath: Path): Path;
store(relativeOrAbsolutePathToFile: Path, data: string | NodeJS.ArrayBufferView, encoding?: WriteFileOptions): Promise<Path>;

@@ -16,0 +17,0 @@ createReadStream(relativeOrAbsolutePathToFile: Path): nodeFS.ReadStream;

17

lib/io/FileSystem.js

@@ -43,23 +43,26 @@ "use strict";

}
resolve(relativeOrAbsolutePath) {
return this.root.resolve(relativeOrAbsolutePath);
}
store(relativeOrAbsolutePathToFile, data, encoding) {
return Promise.resolve()
.then(() => this.ensureDirectoryExistsAt(relativeOrAbsolutePathToFile.directory()))
.then(() => this.write(this.root.resolve(relativeOrAbsolutePathToFile), data, encoding));
.then(() => this.write(this.resolve(relativeOrAbsolutePathToFile), data, encoding));
}
createReadStream(relativeOrAbsolutePathToFile) {
return this.fs.createReadStream(this.root.resolve(relativeOrAbsolutePathToFile).value);
return this.fs.createReadStream(this.resolve(relativeOrAbsolutePathToFile).value);
}
createWriteStreamTo(relativeOrAbsolutePathToFile) {
return this.fs.createWriteStream(this.root.resolve(relativeOrAbsolutePathToFile).value);
return this.fs.createWriteStream(this.resolve(relativeOrAbsolutePathToFile).value);
}
stat(relativeOrAbsolutePathToFile) {
const stat = (0, util_1.promisify)(this.fs.stat);
return stat(this.root.resolve(relativeOrAbsolutePathToFile).value);
return stat(this.resolve(relativeOrAbsolutePathToFile).value);
}
exists(relativeOrAbsolutePathToFile) {
return this.fs.existsSync(this.root.resolve(relativeOrAbsolutePathToFile).value);
return this.fs.existsSync(this.resolve(relativeOrAbsolutePathToFile).value);
}
remove(relativeOrAbsolutePathToFileOrDirectory) {
const stat = (0, util_1.promisify)(this.fs.stat), unlink = (0, util_1.promisify)(this.fs.unlink), readdir = (0, util_1.promisify)(this.fs.readdir), rmdir = (0, util_1.promisify)(this.fs.rmdir);
const absolutePath = this.root.resolve(relativeOrAbsolutePathToFileOrDirectory);
const absolutePath = this.resolve(relativeOrAbsolutePathToFileOrDirectory);
return stat(absolutePath.value)

@@ -79,3 +82,3 @@ .then(result => result.isFile()

ensureDirectoryExistsAt(relativeOrAbsolutePathToDirectory) {
const absolutePath = this.root.resolve(relativeOrAbsolutePathToDirectory);
const absolutePath = this.resolve(relativeOrAbsolutePathToDirectory);
return absolutePath.split().reduce((promisedParent, child) => {

@@ -82,0 +85,0 @@ return promisedParent.then(parent => new Promise((resolve, reject) => {

@@ -10,3 +10,4 @@ import type { ClassDescription } from '../../config';

instantiate<T>(description: ClassDescription): T;
private ensureDefined;
}
//# sourceMappingURL=ClassLoader.d.ts.map

@@ -23,12 +23,34 @@ "use strict";

}
if (descriptor.parameter) {
if (typeof requiredType.fromJSON !== 'function') {
throw new errors_1.ConfigurationError((0, format_1.d) `Class ${descriptor.className} exported by ${descriptor.moduleId} needs a static fromJSON() method that accepts ${descriptor.parameter}`);
const needsParameter = Boolean(descriptor.parameter);
if (needsParameter && typeof requiredType.fromJSON === 'function') {
return this.ensureDefined(requiredType.fromJSON(descriptor.parameter), `${requiredType}.fromJSON(${descriptor.parameter})`);
}
if (needsParameter && requiredType.length > 1) {
throw new errors_1.ConfigurationError((0, format_1.d) `${descriptor.className} exported by ${descriptor.moduleId} must be a class with a static fromJSON(config) method or a function that accepts a single config parameter: ${descriptor.parameter}`);
}
if (!needsParameter && requiredType.length > 0) {
throw new errors_1.ConfigurationError((0, format_1.d) `${descriptor.className} exported by ${descriptor.moduleId} must be a parameterless function since no config parameter is specified`);
}
try {
return this.ensureDefined(requiredType(descriptor.parameter), `${requiredType}(${descriptor.parameter})`);
}
catch (error) {
if (error instanceof TypeError && error.message.includes('constructor')) {
return new requiredType(descriptor.parameter);
}
return requiredType.fromJSON(descriptor.parameter);
const errorMessage = [
(0, format_1.d) `${descriptor.className} exported by ${descriptor.moduleId} must be either:`,
descriptor.parameter && (0, format_1.d) `- a class with a static fromJSON(config) method`,
descriptor.parameter ? '- a no-arg constructor function' : '- a constructor function accepting config',
descriptor.parameter ? '- a no-arg function' : '- a function accepting config',
descriptor.parameter && (0, format_1.d) `where config is: ${descriptor.parameter}`,
].filter(Boolean).join('\n');
throw new errors_1.ConfigurationError(errorMessage);
}
if (requiredType.length > 0) {
throw new errors_1.ConfigurationError((0, format_1.d) `Class ${descriptor.className} exported by ${descriptor.moduleId} doesn't seem to offer a no-arg constructor`);
}
ensureDefined(value, operation) {
if (value === undefined || value === null) {
throw new errors_1.ConfigurationError(`Calling ${operation} produced ${value}, which might indicate a configuration or programming error`);
}
return new requiredType();
return value;
}

@@ -35,0 +57,0 @@ }

@@ -33,2 +33,3 @@ /// <reference types="node" />

toJSON(): string;
toISOString(): string;
toString(): string;

@@ -35,0 +36,0 @@ [inspect.custom](): string;

@@ -78,5 +78,8 @@ "use strict";

}
toString() {
toISOString() {
return this.value.toISOString();
}
toString() {
return this.toISOString();
}
[util_1.inspect.custom]() {

@@ -83,0 +86,0 @@ return `Timestamp(${this.value.toISOString()})`;

@@ -18,2 +18,3 @@ import type { SerenityConfig } from './config';

private stage;
private readonly fileSystem;
private outputStream;

@@ -24,2 +25,3 @@ private readonly classLoader;

* @param clock
* @param cwd
*/

@@ -26,0 +28,0 @@ constructor(clock?: Clock, cwd?: string);

@@ -20,2 +20,3 @@ "use strict";

stage;
fileSystem;
outputStream = process.stdout;

@@ -26,2 +27,3 @@ classLoader;

* @param clock
* @param cwd
*/

@@ -33,2 +35,3 @@ constructor(clock = new screenplay_1.Clock(), cwd = process.cwd()) {

this.workingDirectory = new io_1.Path(cwd);
this.fileSystem = new io_1.FileSystem(this.workingDirectory);
}

@@ -65,3 +68,7 @@ /**

if (looksLikeBuilder(stageCrewMember)) {
return stageCrewMember.build({ stage: this.stage, outputStream: this.outputStream });
return stageCrewMember.build({
stage: this.stage,
fileSystem: this.fileSystem,
outputStream: this.outputStream,
});
}

@@ -68,0 +75,0 @@ if (looksLikeStageCrewMember(stageCrewMember)) {

import type { OutputStream } from '../adapter';
import type { FileSystem } from '../io';
import type { Stage } from './Stage';

@@ -13,4 +14,5 @@ /**

stage: Stage;
fileSystem: FileSystem;
outputStream: OutputStream;
}
//# sourceMappingURL=StageCrewMemberBuilderDependencies.d.ts.map
{
"name": "@serenity-js/core",
"version": "3.14.2",
"version": "3.15.0",
"description": "Serenity/JS Screenplay, reporting engine and core interfaces.",

@@ -43,3 +43,3 @@ "author": {

"graceful-fs": "4.2.11",
"moment": "2.29.4",
"moment": "2.30.1",
"semver": "7.5.4",

@@ -58,3 +58,3 @@ "tiny-types": "1.21.0",

"assertion-error-formatter": "3.0.0",
"c8": "8.0.1",
"c8": "9.0.0",
"memfs": "4.6.0",

@@ -77,3 +77,3 @@ "mocha": "10.2.0",

},
"gitHead": "b2b052ea1120bf33c2848956f2f0ea5f0ffdfc24"
"gitHead": "f3580d6b6380e9f175544929b9504a85c1d204ad"
}

@@ -15,3 +15,3 @@ # Serenity/JS

- [API documentation](https://serenity-js.org/api/core)
- [Serenity/JS Project Templates on GitHub](https://serenity-js.org/handbook/getting-started#serenityjs-project-templates)
- [Serenity/JS Project Templates on GitHub](https://serenity-js.org/handbook/getting-started/project-templates/)

@@ -18,0 +18,0 @@ 👋 Join the Serenity/JS Community!

@@ -20,14 +20,18 @@ import { createId } from '@paralleldrive/cuid2';

public resolve(relativeOrAbsolutePath: Path): Path {
return this.root.resolve(relativeOrAbsolutePath);
}
public store(relativeOrAbsolutePathToFile: Path, data: string | NodeJS.ArrayBufferView, encoding?: WriteFileOptions): Promise<Path> {
return Promise.resolve()
.then(() => this.ensureDirectoryExistsAt(relativeOrAbsolutePathToFile.directory()))
.then(() => this.write(this.root.resolve(relativeOrAbsolutePathToFile), data, encoding));
.then(() => this.write(this.resolve(relativeOrAbsolutePathToFile), data, encoding));
}
public createReadStream(relativeOrAbsolutePathToFile: Path): nodeFS.ReadStream {
return this.fs.createReadStream(this.root.resolve(relativeOrAbsolutePathToFile).value);
return this.fs.createReadStream(this.resolve(relativeOrAbsolutePathToFile).value);
}
public createWriteStreamTo(relativeOrAbsolutePathToFile: Path): nodeFS.WriteStream {
return this.fs.createWriteStream(this.root.resolve(relativeOrAbsolutePathToFile).value);
return this.fs.createWriteStream(this.resolve(relativeOrAbsolutePathToFile).value);
}

@@ -38,7 +42,7 @@

return stat(this.root.resolve(relativeOrAbsolutePathToFile).value);
return stat(this.resolve(relativeOrAbsolutePathToFile).value);
}
public exists(relativeOrAbsolutePathToFile: Path): boolean {
return this.fs.existsSync(this.root.resolve(relativeOrAbsolutePathToFile).value);
return this.fs.existsSync(this.resolve(relativeOrAbsolutePathToFile).value);
}

@@ -53,3 +57,3 @@

const absolutePath = this.root.resolve(relativeOrAbsolutePathToFileOrDirectory);
const absolutePath = this.resolve(relativeOrAbsolutePathToFileOrDirectory);

@@ -78,3 +82,3 @@ return stat(absolutePath.value)

const absolutePath = this.root.resolve(relativeOrAbsolutePathToDirectory);
const absolutePath = this.resolve(relativeOrAbsolutePathToDirectory);

@@ -81,0 +85,0 @@ return absolutePath.split().reduce((promisedParent, child) => {

@@ -28,16 +28,47 @@ import type { ClassDescription } from '../../config';

if (descriptor.parameter) {
if (typeof requiredType.fromJSON !== 'function') {
throw new ConfigurationError(d `Class ${ descriptor.className } exported by ${ descriptor.moduleId } needs a static fromJSON() method that accepts ${ descriptor.parameter }`);
const needsParameter = Boolean(descriptor.parameter);
if (needsParameter && typeof requiredType.fromJSON === 'function') {
return this.ensureDefined(requiredType.fromJSON(descriptor.parameter), `${ requiredType }.fromJSON(${ descriptor.parameter })`);
}
if (needsParameter && requiredType.length > 1) {
throw new ConfigurationError(d`${ descriptor.className } exported by ${ descriptor.moduleId } must be a class with a static fromJSON(config) method or a function that accepts a single config parameter: ${ descriptor.parameter }`);
}
if (! needsParameter && requiredType.length > 0) {
throw new ConfigurationError(d`${ descriptor.className } exported by ${ descriptor.moduleId } must be a parameterless function since no config parameter is specified`);
}
try {
return this.ensureDefined(
requiredType(descriptor.parameter),
`${ requiredType }(${ descriptor.parameter })`
);
}
catch (error) {
if (error instanceof TypeError && error.message.includes('constructor')) {
return new requiredType(descriptor.parameter);
}
return requiredType.fromJSON(descriptor.parameter);
const errorMessage = [
d`${ descriptor.className } exported by ${ descriptor.moduleId } must be either:`,
descriptor.parameter && d`- a class with a static fromJSON(config) method`,
descriptor.parameter ? '- a no-arg constructor function' : '- a constructor function accepting config',
descriptor.parameter ? '- a no-arg function' : '- a function accepting config',
descriptor.parameter && d`where config is: ${ descriptor.parameter }`,
].filter(Boolean).join('\n');
throw new ConfigurationError(errorMessage);
}
}
if (requiredType.length > 0) {
throw new ConfigurationError(d`Class ${ descriptor.className } exported by ${ descriptor.moduleId } doesn't seem to offer a no-arg constructor`);
private ensureDefined<T>(value: T | undefined, operation: string): T {
if (value === undefined || value === null) {
throw new ConfigurationError(`Calling ${ operation } produced ${ value }, which might indicate a configuration or programming error`);
}
return new requiredType();
return value;
}
}

@@ -87,6 +87,10 @@ import moment from 'moment';

toString(): string {
toISOString(): string {
return this.value.toISOString();
}
toString(): string {
return this.toISOString();
}
[inspect.custom](): string {

@@ -93,0 +97,0 @@ return `Timestamp(${ this.value.toISOString() })`;

@@ -8,3 +8,3 @@ import { ensure, isDefined, isInstanceOf, property } from 'tiny-types';

import type { DomainEvent, EmitsDomainEvents } from './events';
import { ClassDescriptionParser, ClassLoader, d, has, ModuleLoader, Path } from './io';
import { ClassDescriptionParser, ClassLoader, d, FileSystem, has, ModuleLoader, Path } from './io';
import type { ActivityDetails, CorrelationId } from './model';

@@ -28,2 +28,3 @@ import type { Actor, Timestamp } from './screenplay';

private stage: Stage;
private readonly fileSystem: FileSystem;
private outputStream: OutputStream = process.stdout;

@@ -36,2 +37,3 @@

* @param clock
* @param cwd
*/

@@ -56,2 +58,4 @@ constructor(

this.workingDirectory = new Path(cwd);
this.fileSystem = new FileSystem(this.workingDirectory);
}

@@ -104,3 +108,7 @@

if (looksLikeBuilder(stageCrewMember)) {
return stageCrewMember.build({ stage: this.stage, outputStream: this.outputStream });
return stageCrewMember.build({
stage: this.stage,
fileSystem: this.fileSystem,
outputStream: this.outputStream,
});
}

@@ -107,0 +115,0 @@

import type { OutputStream } from '../adapter';
import type { FileSystem } from '../io';
import type { Stage } from './Stage';

@@ -14,3 +15,4 @@

stage: Stage;
fileSystem: FileSystem;
outputStream: OutputStream;
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc