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.15.1 to 3.16.0

lib/io/RequirementsHierarchy.d.ts

22

CHANGELOG.md

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

# [3.16.0](https://github.com/serenity-js/serenity-js/compare/v3.15.1...v3.16.0) (2024-02-01)
### Bug Fixes
* **core:** introduced RequirementsHierarchy to centralise requirements detection logic ([0a3d6f0](https://github.com/serenity-js/serenity-js/commit/0a3d6f013a3b94ca471edc263e1157b7c41131be))
* **core:** recognise `specs` as a potential requirements hierarchy root ([d95d850](https://github.com/serenity-js/serenity-js/commit/d95d85058fd5e4e01aec689b7196989ece5e303f))
* **core:** removed dependency on Moment.js ([edd1d64](https://github.com/serenity-js/serenity-js/commit/edd1d64f30893983b92bd600d102c81577c0ecb1))
* **core:** simplified the Timestampt validation regex and improved error messages ([b453a23](https://github.com/serenity-js/serenity-js/commit/b453a23de419dbd811927b9447c17678e39f8cc8))
* **core:** support for timezones and simplified date time strings when creating Timestamps ([754f8e2](https://github.com/serenity-js/serenity-js/commit/754f8e260d2fc5130075a78ec58084eafcf2c83f))
### Features
* **core:** added Masked.valueOf() Question ([e9ff5ab](https://github.com/serenity-js/serenity-js/commit/e9ff5ab62e8b305aa7ef2238f482be5369d890c1)), closes [#2165](https://github.com/serenity-js/serenity-js/issues/2165)
* **mocha:** support for nested requirements reporting ([f8e70ce](https://github.com/serenity-js/serenity-js/commit/f8e70ce8a317ab6e8bdf4d058110f110b4c8deda))
* **serenity-bdd:** upgraded Serenity BDD to 4.0.44 ([4e2f1e3](https://github.com/serenity-js/serenity-js/commit/4e2f1e3b273712c44a7f749ba9570f121520cdd5))
## [3.15.1](https://github.com/serenity-js/serenity-js/compare/v3.15.0...v3.15.1) (2024-01-19)

@@ -8,0 +30,0 @@

1

lib/io/index.d.ts

@@ -13,3 +13,4 @@ export * from './asyncMap';

export * from './reflection';
export * from './RequirementsHierarchy';
export * from './trimmed';
//# sourceMappingURL=index.d.ts.map

@@ -29,3 +29,4 @@ "use strict";

__exportStar(require("./reflection"), exports);
__exportStar(require("./RequirementsHierarchy"), exports);
__exportStar(require("./trimmed"), exports);
//# sourceMappingURL=index.js.map

2

lib/model/tags/Tag.js

@@ -39,3 +39,3 @@ "use strict";

.trim()
.match(/[\dA-Z]{2,}(?=[A-Z][a-z]+\d*|\b)|[A-Z]?[a-z]+\d*|[A-Z]|\d+/g)
.match(/[\dA-Z]{2,}(?=[A-Z][a-z]+\d*|\b)|[A-Z]?[a-z-]+\d*|[A-Z]|\d+/g)
.map(chunk => /^[A-Z]+$/.test(chunk) ? chunk : chunk.toLowerCase())

@@ -42,0 +42,0 @@ .join('_')

@@ -119,6 +119,3 @@ import type { Artifact } from '../model';

/**
* Announce collection of an {@apilink Artifact} so that it can be picked up by a {@apilink StageCrewMember}.
*
* @param artifact
* @param name
* @inheritDoc
*/

@@ -125,0 +122,0 @@ collect(artifact: Artifact, name?: string | Name): void;

@@ -143,6 +143,3 @@ "use strict";

/**
* Announce collection of an {@apilink Artifact} so that it can be picked up by a {@apilink StageCrewMember}.
*
* @param artifact
* @param name
* @inheritDoc
*/

@@ -149,0 +146,0 @@ collect(artifact, name) {

@@ -16,2 +16,56 @@ import type { Artifact, Name } from '../../model';

*
* #### Implementing a custom interaction to attach artifacts
*
* ```ts
* import * as fs from 'node:fs'
* import { Answerable, Interaction } from '@serenity-js/core'
* import { Path } from '@serenity-js/core/lib/io'
* import { Name, TextData } from '@serenity-js/core/lib/model'
*
* export class Attach {
*
* static contentsOf = (pathToFile: Path): Interaction =>
* Interaction.where(`#actor attaches contents of ${ pathToFile.basename() }`, async actor => {
* const data = fs.readFileSync(pathToFile.value).toString('utf-8');
*
* actor.collect(
* TextData.fromJSON({ contentType: 'text/plain', data }),
* new Name(pathToFile.basename()),
* )
* })
*
* static textData = (contents: Answerable<string>, name?: string): Interaction =>
* Interaction.where(`#actor attaches text data`, async actor => {
* const data = await actor.answer(contents);
*
* actor.collect(
* TextData.fromJSON({ contentType: 'text/plain', data }),
* name && new Name(name),
* )
* })
* }
* ```
*
* #### Attaching plain text
*
* ```ts
* import { actorCalled } from '@serenity-js/core'
* import { Path } from '@serenity-js/core/lib/io'
*
* actorCalled('Alice').attemptsTo(
* Attach.textData('some text', 'some name'),
* )
* ```
*
* #### Attaching contents of a text file
*
* ```ts
* import { actorCalled } from '@serenity-js/core'
* import { Log } from '@serenity-js/core'
*
* actorCalled('Alice').attemptsTo(
* Attach.contentsOf(Path.from(__dirname, 'output/server.log')),
* )
* ```
*
* @param artifact

@@ -18,0 +72,0 @@ * The artifact to be collected, such as {@apilink JSONData}

@@ -7,2 +7,3 @@ export * from './AnswersQuestions';

export * from './List';
export * from './Masked';
export * from './MetaQuestion';

@@ -9,0 +10,0 @@ export * from './q';

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

__exportStar(require("./List"), exports);
__exportStar(require("./Masked"), exports);
__exportStar(require("./MetaQuestion"), exports);

@@ -25,0 +26,0 @@ __exportStar(require("./q"), exports);

@@ -19,4 +19,4 @@ /// <reference types="node" />

static fromJSON(v: string): Timestamp;
static fromTimestampInSeconds(v: number): Timestamp;
static fromTimestampInMilliseconds(v: number): Timestamp;
static fromTimestampInSeconds(value: number): Timestamp;
static fromTimestampInMilliseconds(value: number): Timestamp;
static now(): Timestamp;

@@ -23,0 +23,0 @@ constructor(value?: Date);

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Timestamp = void 0;
const moment_1 = __importDefault(require("moment"));
const tiny_types_1 = require("tiny-types");

@@ -27,7 +23,7 @@ const util_1 = require("util");

}
static fromTimestampInSeconds(v) {
return Timestamp.fromTimestampInMilliseconds(v * 1000);
static fromTimestampInSeconds(value) {
return Timestamp.fromTimestampInMilliseconds(value * 1000);
}
static fromTimestampInMilliseconds(v) {
return new Timestamp((0, moment_1.default)(v).toDate());
static fromTimestampInMilliseconds(value) {
return new Timestamp(new Date(value));
}

@@ -44,11 +40,11 @@ static now() {

(0, tiny_types_1.ensure)('timestamp', another, (0, tiny_types_1.isDefined)());
return new Duration_1.Duration(Math.abs((0, moment_1.default)(this.value).diff(another.value, 'ms', true)));
return new Duration_1.Duration(Math.abs(this.toMilliseconds() - another.toMilliseconds()));
}
plus(duration) {
(0, tiny_types_1.ensure)('duration', duration, (0, tiny_types_1.isDefined)());
return new Timestamp((0, moment_1.default)(this.value).add(duration.inMilliseconds(), 'ms').toDate());
return new Timestamp(new Date(this.toMilliseconds() + duration.inMilliseconds()));
}
less(duration) {
(0, tiny_types_1.ensure)('duration', duration, (0, tiny_types_1.isDefined)());
return new Timestamp((0, moment_1.default)(this.value).subtract(duration.inMilliseconds(), 'ms').toDate());
return new Timestamp(new Date(this.toMilliseconds() - duration.inMilliseconds()));
}

@@ -72,6 +68,6 @@ isBefore(another) {

toMilliseconds() {
return (0, moment_1.default)(this.value).valueOf();
return this.value.getTime();
}
toSeconds() {
return (0, moment_1.default)(this.value).unix();
return Math.floor(this.toMilliseconds() / 1000);
}

@@ -92,5 +88,34 @@ toJSON() {

exports.Timestamp = Timestamp;
/**
* Based on the implementation by Brock Adams:
* - https://stackoverflow.com/a/3143231/264502 by Brock Adams
* - https://www.w3.org/TR/NOTE-datetime
*/
function isSerialisedISO8601Date() {
return tiny_types_1.Predicate.to(`be an ISO-8601-compliant date`, (value) => (0, moment_1.default)(value, moment_1.default.ISO_8601, true).isValid());
const yyyyMMdd = `\\d{4}-[01]\\d-[0-3]\\d`;
const hh = `[0-2]\\d`;
const mm = `[0-5]\\d`;
const ss = `[0-5]\\d`;
const ms = `\\d+`;
const T = `[Tt\\s]`;
const offset = `[+-]${hh}:${mm}|Z`;
const pattern = new RegExp('^' + [
// Full precision - YYYY-MM-DDThh:mm:ss.sss
`(${yyyyMMdd}${T}${hh}:${mm}:${ss}\\.${ms}(${offset})?)`,
// No milliseconds - YYYY-MM-DDThh:mm:ss
`(${yyyyMMdd}${T}${hh}:${mm}:${ss}(${offset})?)`,
// No seconds - YYYY-MM-DDThh:mm
`(${yyyyMMdd}${T}${hh}:${mm}(${offset})?)`,
// Just the date - YYYY-MM-DD
`(${yyyyMMdd})`,
].join('|') + '$');
return tiny_types_1.Predicate.to(`follow the ISO8601 format: YYYY-MM-DD[Thh:mm[:ss[.sss]]]`, (value) => {
if (!pattern.test(value)) {
return false;
}
const date = new Date(value);
return date instanceof Date
&& !Number.isNaN(date.getTime());
});
}
//# sourceMappingURL=Timestamp.js.map
{
"name": "@serenity-js/core",
"version": "3.15.1",
"version": "3.16.0",
"description": "Serenity/JS Screenplay, reporting engine and core interfaces.",

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

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

@@ -76,3 +75,3 @@ "tiny-types": "1.21.0",

},
"gitHead": "4df79de3820acd9fb18d76843feb0468c55c8e7f"
"gitHead": "242771e55bd6becc5baeaac03edf945e4cdaf7a4"
}

@@ -13,2 +13,3 @@ export * from './asyncMap';

export * from './reflection';
export * from './RequirementsHierarchy';
export * from './trimmed';

@@ -14,3 +14,3 @@ import type { JSONObject} from 'tiny-types';

.trim()
.match(/[\dA-Z]{2,}(?=[A-Z][a-z]+\d*|\b)|[A-Z]?[a-z]+\d*|[A-Z]|\d+/g)
.match(/[\dA-Z]{2,}(?=[A-Z][a-z]+\d*|\b)|[A-Z]?[a-z-]+\d*|[A-Z]|\d+/g)
.map(chunk => /^[A-Z]+$/.test(chunk) ? chunk : chunk.toLowerCase())

@@ -17,0 +17,0 @@ .join('_')

@@ -177,6 +177,3 @@ import { ConfigurationError, TestCompromisedError } from '../errors';

/**
* Announce collection of an {@apilink Artifact} so that it can be picked up by a {@apilink StageCrewMember}.
*
* @param artifact
* @param name
* @inheritDoc
*/

@@ -183,0 +180,0 @@ collect(artifact: Artifact, name?: string | Name): void {

@@ -18,2 +18,56 @@ import type { Artifact, Name } from '../../model';

*
* #### Implementing a custom interaction to attach artifacts
*
* ```ts
* import * as fs from 'node:fs'
* import { Answerable, Interaction } from '@serenity-js/core'
* import { Path } from '@serenity-js/core/lib/io'
* import { Name, TextData } from '@serenity-js/core/lib/model'
*
* export class Attach {
*
* static contentsOf = (pathToFile: Path): Interaction =>
* Interaction.where(`#actor attaches contents of ${ pathToFile.basename() }`, async actor => {
* const data = fs.readFileSync(pathToFile.value).toString('utf-8');
*
* actor.collect(
* TextData.fromJSON({ contentType: 'text/plain', data }),
* new Name(pathToFile.basename()),
* )
* })
*
* static textData = (contents: Answerable<string>, name?: string): Interaction =>
* Interaction.where(`#actor attaches text data`, async actor => {
* const data = await actor.answer(contents);
*
* actor.collect(
* TextData.fromJSON({ contentType: 'text/plain', data }),
* name && new Name(name),
* )
* })
* }
* ```
*
* #### Attaching plain text
*
* ```ts
* import { actorCalled } from '@serenity-js/core'
* import { Path } from '@serenity-js/core/lib/io'
*
* actorCalled('Alice').attemptsTo(
* Attach.textData('some text', 'some name'),
* )
* ```
*
* #### Attaching contents of a text file
*
* ```ts
* import { actorCalled } from '@serenity-js/core'
* import { Log } from '@serenity-js/core'
*
* actorCalled('Alice').attemptsTo(
* Attach.contentsOf(Path.from(__dirname, 'output/server.log')),
* )
* ```
*
* @param artifact

@@ -20,0 +74,0 @@ * The artifact to be collected, such as {@apilink JSONData}

@@ -7,4 +7,5 @@ export * from './AnswersQuestions';

export * from './List';
export * from './Masked';
export * from './MetaQuestion';
export * from './q';
export * from './Unanswered';

@@ -1,2 +0,1 @@

import moment from 'moment';
import { ensure, isDefined, isInstanceOf, Predicate, TinyType } from 'tiny-types';

@@ -23,8 +22,8 @@ import { inspect } from 'util';

static fromTimestampInSeconds(v: number): Timestamp {
return Timestamp.fromTimestampInMilliseconds(v * 1000);
static fromTimestampInSeconds(value: number): Timestamp {
return Timestamp.fromTimestampInMilliseconds(value * 1000);
}
static fromTimestampInMilliseconds(v: number): Timestamp {
return new Timestamp(moment(v).toDate());
static fromTimestampInMilliseconds(value: number): Timestamp {
return new Timestamp(new Date(value));
}

@@ -43,3 +42,3 @@

ensure('timestamp', another, isDefined());
return new Duration(Math.abs(moment(this.value).diff(another.value, 'ms', true)));
return new Duration(Math.abs(this.toMilliseconds() - another.toMilliseconds()));
}

@@ -49,3 +48,3 @@

ensure('duration', duration, isDefined());
return new Timestamp(moment(this.value).add(duration.inMilliseconds(), 'ms').toDate());
return new Timestamp(new Date(this.toMilliseconds() + duration.inMilliseconds()));
}

@@ -55,3 +54,3 @@

ensure('duration', duration, isDefined());
return new Timestamp(moment(this.value).subtract(duration.inMilliseconds(), 'ms').toDate());
return new Timestamp(new Date(this.toMilliseconds() - duration.inMilliseconds()));
}

@@ -80,7 +79,7 @@

toMilliseconds(): number {
return moment(this.value).valueOf();
return this.value.getTime();
}
toSeconds(): number {
return moment(this.value).unix();
return Math.floor(this.toMilliseconds() / 1_000);
}

@@ -105,5 +104,39 @@

/**
* Based on the implementation by Brock Adams:
* - https://stackoverflow.com/a/3143231/264502 by Brock Adams
* - https://www.w3.org/TR/NOTE-datetime
*/
function isSerialisedISO8601Date(): Predicate<string> {
return Predicate.to(`be an ISO-8601-compliant date`, (value: string) =>
moment(value, moment.ISO_8601, true).isValid());
const yyyyMMdd = `\\d{4}-[01]\\d-[0-3]\\d`;
const hh = `[0-2]\\d`;
const mm = `[0-5]\\d`;
const ss = `[0-5]\\d`;
const ms = `\\d+`;
const T = `[Tt\\s]`;
const offset = `[+-]${hh}:${mm}|Z`;
const pattern = new RegExp('^' + [
// Full precision - YYYY-MM-DDThh:mm:ss.sss
`(${yyyyMMdd}${T}${hh}:${mm}:${ss}\\.${ms}(${offset})?)`,
// No milliseconds - YYYY-MM-DDThh:mm:ss
`(${yyyyMMdd}${T}${hh}:${mm}:${ss}(${offset})?)`,
// No seconds - YYYY-MM-DDThh:mm
`(${yyyyMMdd}${T}${hh}:${mm}(${offset})?)`,
// Just the date - YYYY-MM-DD
`(${yyyyMMdd})`,
].join('|') + '$');
return Predicate.to(`follow the ISO8601 format: YYYY-MM-DD[Thh:mm[:ss[.sss]]]`, (value: string) => {
if (! pattern.test(value)) {
return false;
}
const date = new Date(value);
return date instanceof Date
&& ! Number.isNaN(date.getTime());
});
}

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

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