laymos 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -3
- package/dist/architecture/analyze-project/analyze-project.d.ts +0 -9
- package/dist/architecture/analyze-project/analyze-project.d.ts.map +0 -1
- package/dist/architecture/analyze-project/analyze-project.js +0 -47
- package/dist/architecture/analyze-project/index.d.ts +0 -3
- package/dist/architecture/analyze-project/index.d.ts.map +0 -1
- package/dist/architecture/analyze-project/index.js +0 -1
- package/dist/architecture/build-report/build-report.d.ts +0 -7
- package/dist/architecture/build-report/build-report.d.ts.map +0 -1
- package/dist/architecture/build-report/build-report.js +0 -80
- package/dist/architecture/build-report/index.d.ts +0 -2
- package/dist/architecture/build-report/index.d.ts.map +0 -1
- package/dist/architecture/build-report/index.js +0 -1
- package/dist/architecture/errors.d.ts +0 -11
- package/dist/architecture/errors.d.ts.map +0 -1
- package/dist/architecture/errors.js +0 -3
- package/dist/architecture/extract-dependencies/extract-dependencies.d.ts +0 -12
- package/dist/architecture/extract-dependencies/extract-dependencies.d.ts.map +0 -1
- package/dist/architecture/extract-dependencies/extract-dependencies.js +0 -162
- package/dist/architecture/extract-dependencies/index.d.ts +0 -3
- package/dist/architecture/extract-dependencies/index.d.ts.map +0 -1
- package/dist/architecture/extract-dependencies/index.js +0 -1
- package/dist/architecture/resolve-architecture/index.d.ts +0 -3
- package/dist/architecture/resolve-architecture/index.d.ts.map +0 -1
- package/dist/architecture/resolve-architecture/index.js +0 -1
- package/dist/architecture/resolve-architecture/resolve-architecture.d.ts +0 -24
- package/dist/architecture/resolve-architecture/resolve-architecture.d.ts.map +0 -1
- package/dist/architecture/resolve-architecture/resolve-architecture.js +0 -74
- package/dist/architecture/validate-rules/index.d.ts +0 -3
- package/dist/architecture/validate-rules/index.d.ts.map +0 -1
- package/dist/architecture/validate-rules/index.js +0 -1
- package/dist/architecture/validate-rules/validate-rules.d.ts +0 -10
- package/dist/architecture/validate-rules/validate-rules.d.ts.map +0 -1
- package/dist/architecture/validate-rules/validate-rules.js +0 -80
- package/dist/cli/deps/dependency-tree.d.ts +0 -3
- package/dist/cli/deps/dependency-tree.d.ts.map +0 -1
- package/dist/cli/deps/dependency-tree.js +0 -39
- package/dist/cli/deps/deps.d.ts +0 -7
- package/dist/cli/deps/deps.d.ts.map +0 -1
- package/dist/cli/deps/deps.js +0 -26
- package/dist/cli/deps/index.d.ts +0 -2
- package/dist/cli/deps/index.d.ts.map +0 -1
- package/dist/cli/deps/index.js +0 -2
- package/dist/config/define-config.d.ts +0 -8
- package/dist/config/define-config.d.ts.map +0 -1
- package/dist/config/define-config.js +0 -373
- package/dist/config/index.d.ts +0 -11
- package/dist/config/index.d.ts.map +0 -1
- package/dist/config/index.js +0 -6
- package/dist/config/layer-graph.d.ts +0 -7
- package/dist/config/layer-graph.d.ts.map +0 -1
- package/dist/config/layer-graph.js +0 -26
- package/dist/config/layer.d.ts +0 -5
- package/dist/config/layer.d.ts.map +0 -1
- package/dist/config/layer.js +0 -8
- package/dist/config/load-config/index.d.ts +0 -2
- package/dist/config/load-config/index.d.ts.map +0 -1
- package/dist/config/load-config/index.js +0 -1
- package/dist/config/load-config/load-config.d.ts +0 -34
- package/dist/config/load-config/load-config.d.ts.map +0 -1
- package/dist/config/load-config/load-config.js +0 -127
- package/dist/config/module.d.ts +0 -11
- package/dist/config/module.d.ts.map +0 -1
- package/dist/config/module.js +0 -22
- package/dist/config/path.d.ts +0 -4
- package/dist/config/path.d.ts.map +0 -1
- package/dist/config/path.js +0 -32
- package/dist/config/project-narrative.d.ts +0 -15
- package/dist/config/project-narrative.d.ts.map +0 -1
- package/dist/config/project-narrative.js +0 -11
- package/dist/config/types.d.ts +0 -38
- package/dist/config/types.d.ts.map +0 -1
- package/dist/config/types.js +0 -1
- package/dist/domain/architecture-analysis/modules/unexposed-modules.d.ts +0 -3
- package/dist/domain/architecture-analysis/modules/unexposed-modules.d.ts.map +0 -1
- package/dist/domain/architecture-analysis/modules/unexposed-modules.js +0 -10
- package/dist/domain/project-config/validation/modules/containment.d.ts +0 -3
- package/dist/domain/project-config/validation/modules/containment.d.ts.map +0 -1
- package/dist/domain/project-config/validation/modules/containment.js +0 -24
- package/dist/domain/project-config/validation/modules/kinds.d.ts +0 -3
- package/dist/domain/project-config/validation/modules/kinds.d.ts.map +0 -1
- package/dist/domain/project-config/validation/modules/kinds.js +0 -18
- package/dist/domain/project-config/validation/modules/nested.d.ts +0 -3
- package/dist/domain/project-config/validation/modules/nested.d.ts.map +0 -1
- package/dist/domain/project-config/validation/modules/nested.js +0 -34
- package/dist/domain/project-config/validation/modules/subpaths.d.ts +0 -3
- package/dist/domain/project-config/validation/modules/subpaths.d.ts.map +0 -1
- package/dist/domain/project-config/validation/modules/subpaths.js +0 -40
- package/dist/entrypoints/cli/cli.d.ts +0 -3
- package/dist/entrypoints/cli/cli.d.ts.map +0 -1
- package/dist/entrypoints/cli/cli.js +0 -6
- package/dist/entrypoints/cli/run.d.ts +0 -13
- package/dist/entrypoints/cli/run.d.ts.map +0 -1
- package/dist/entrypoints/cli/run.js +0 -155
- package/dist/entrypoints/cli/test-output.d.ts +0 -17
- package/dist/entrypoints/cli/test-output.d.ts.map +0 -1
- package/dist/entrypoints/cli/test-output.js +0 -244
- package/dist/entrypoints/node/index.d.ts +0 -24
- package/dist/entrypoints/node/index.d.ts.map +0 -1
- package/dist/entrypoints/node/index.js +0 -27
- package/dist/entrypoints/report/index.d.ts +0 -2
- package/dist/entrypoints/report/index.d.ts.map +0 -1
- package/dist/entrypoints/report/index.js +0 -1
- package/dist/markdown/index.d.ts +0 -3
- package/dist/markdown/index.d.ts.map +0 -1
- package/dist/markdown/index.js +0 -1
- package/dist/markdown/markdown.d.ts +0 -7
- package/dist/markdown/markdown.d.ts.map +0 -1
- package/dist/markdown/markdown.js +0 -13
- package/dist/orchestrator/query-dependencies/index.d.ts +0 -3
- package/dist/orchestrator/query-dependencies/index.d.ts.map +0 -1
- package/dist/orchestrator/query-dependencies/index.js +0 -4
- package/dist/orchestrator/query-dependencies/query-dependencies.d.ts +0 -12
- package/dist/orchestrator/query-dependencies/query-dependencies.d.ts.map +0 -1
- package/dist/orchestrator/query-dependencies/query-dependencies.js +0 -20
- package/dist/report/architecture.d.ts +0 -104
- package/dist/report/architecture.d.ts.map +0 -1
- package/dist/report/architecture.js +0 -1
- package/dist/report/index.d.ts +0 -4
- package/dist/report/index.d.ts.map +0 -1
- package/dist/report/index.js +0 -2
- package/dist/report/tests.d.ts +0 -411
- package/dist/report/tests.d.ts.map +0 -1
- package/dist/report/tests.js +0 -102
- package/dist/tests/authoring/index.d.ts +0 -72
- package/dist/tests/authoring/index.d.ts.map +0 -1
- package/dist/tests/authoring/index.js +0 -312
- package/dist/tests/run-tests/index.d.ts +0 -3
- package/dist/tests/run-tests/index.d.ts.map +0 -1
- package/dist/tests/run-tests/index.js +0 -1
- package/dist/tests/run-tests/run-tests.d.ts +0 -26
- package/dist/tests/run-tests/run-tests.d.ts.map +0 -1
- package/dist/tests/run-tests/run-tests.js +0 -284
|
@@ -1,284 +0,0 @@
|
|
|
1
|
-
import { createRequire } from 'node:module';
|
|
2
|
-
import { relative, resolve, sep } from 'node:path';
|
|
3
|
-
import { Writable } from 'node:stream';
|
|
4
|
-
import { pathToFileURL } from 'node:url';
|
|
5
|
-
import { Data, Effect, Option, Schema } from 'effect';
|
|
6
|
-
import { LaymosTestEvidenceSchema, } from '../../report/tests.js';
|
|
7
|
-
export class TestRunInProgress extends Data.TaggedError('TestRunInProgress') {
|
|
8
|
-
}
|
|
9
|
-
export class TestRunnerError extends Data.TaggedError('TestRunnerError') {
|
|
10
|
-
}
|
|
11
|
-
const activeProjects = new Set();
|
|
12
|
-
let activeRunCount = 0;
|
|
13
|
-
let originalExitCode;
|
|
14
|
-
const minimumVitestVersion = [4, 1, 10];
|
|
15
|
-
const silentOutput = new Writable({
|
|
16
|
-
write(_chunk, _encoding, callback) {
|
|
17
|
-
callback();
|
|
18
|
-
},
|
|
19
|
-
});
|
|
20
|
-
const PackageMetadataSchema = Schema.Struct({ version: Schema.String });
|
|
21
|
-
const ErrorInputSchema = Schema.Struct({
|
|
22
|
-
name: Schema.optional(Schema.String),
|
|
23
|
-
message: Schema.String,
|
|
24
|
-
stack: Schema.optional(Schema.String),
|
|
25
|
-
expected: Schema.optional(Schema.String),
|
|
26
|
-
actual: Schema.optional(Schema.String),
|
|
27
|
-
diff: Schema.optional(Schema.String),
|
|
28
|
-
});
|
|
29
|
-
const LaymosTestArtifactSchema = Schema.Struct({
|
|
30
|
-
type: Schema.Literal('laymos:test-evidence'),
|
|
31
|
-
evidence: LaymosTestEvidenceSchema,
|
|
32
|
-
});
|
|
33
|
-
const LaymosTaskMetaSchema = Schema.Struct({
|
|
34
|
-
laymosTest: Schema.Struct({
|
|
35
|
-
description: Schema.String,
|
|
36
|
-
documentation: Schema.optional(Schema.String),
|
|
37
|
-
}),
|
|
38
|
-
});
|
|
39
|
-
const LaymosSuiteMetaSchema = Schema.Struct({
|
|
40
|
-
laymosSuite: Schema.Struct({
|
|
41
|
-
description: Schema.String,
|
|
42
|
-
documentation: Schema.optional(Schema.String),
|
|
43
|
-
}),
|
|
44
|
-
});
|
|
45
|
-
export function executeTests(projectDir, options = {}) {
|
|
46
|
-
const root = resolve(projectDir);
|
|
47
|
-
return Effect.tryPromise({
|
|
48
|
-
try: async () => {
|
|
49
|
-
if (activeProjects.has(root)) {
|
|
50
|
-
throw new TestRunInProgress({
|
|
51
|
-
projectDir: root,
|
|
52
|
-
message: `A Vitest run is already active for "${root}"`,
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
activeProjects.add(root);
|
|
56
|
-
enterVitestRun();
|
|
57
|
-
try {
|
|
58
|
-
return await runVitest(root, options);
|
|
59
|
-
}
|
|
60
|
-
finally {
|
|
61
|
-
activeProjects.delete(root);
|
|
62
|
-
leaveVitestRun();
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
catch: (cause) => cause instanceof TestRunInProgress || cause instanceof TestRunnerError
|
|
66
|
-
? cause
|
|
67
|
-
: new TestRunnerError({ message: errorMessage(cause), cause }),
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
async function runVitest(projectDir, options) {
|
|
71
|
-
const vitestNode = await loadProjectVitest(projectDir);
|
|
72
|
-
const startedAt = performance.now();
|
|
73
|
-
let vitest;
|
|
74
|
-
try {
|
|
75
|
-
vitest = await vitestNode.createVitest('test', {
|
|
76
|
-
root: projectDir,
|
|
77
|
-
watch: false,
|
|
78
|
-
changed: false,
|
|
79
|
-
passWithNoTests: true,
|
|
80
|
-
includeTaskLocation: true,
|
|
81
|
-
...(options.testNamePattern === undefined
|
|
82
|
-
? {}
|
|
83
|
-
: { testNamePattern: options.testNamePattern }),
|
|
84
|
-
}, {}, { stdout: silentOutput, stderr: silentOutput });
|
|
85
|
-
delete vitest.config.related;
|
|
86
|
-
const result = await vitest.start(options.files ? [...options.files] : []);
|
|
87
|
-
return mapRunResult(projectDir, result, performance.now() - startedAt);
|
|
88
|
-
}
|
|
89
|
-
finally {
|
|
90
|
-
await vitest?.close();
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
function enterVitestRun() {
|
|
94
|
-
if (activeRunCount === 0)
|
|
95
|
-
originalExitCode = process.exitCode;
|
|
96
|
-
activeRunCount += 1;
|
|
97
|
-
}
|
|
98
|
-
function leaveVitestRun() {
|
|
99
|
-
activeRunCount -= 1;
|
|
100
|
-
if (activeRunCount === 0)
|
|
101
|
-
process.exitCode = originalExitCode;
|
|
102
|
-
}
|
|
103
|
-
async function loadProjectVitest(projectDir) {
|
|
104
|
-
const require = createRequire(resolve(projectDir, 'package.json'));
|
|
105
|
-
let entrypoint;
|
|
106
|
-
let packageJson;
|
|
107
|
-
try {
|
|
108
|
-
entrypoint = require.resolve('vitest/node');
|
|
109
|
-
packageJson = require.resolve('vitest/package.json');
|
|
110
|
-
}
|
|
111
|
-
catch (cause) {
|
|
112
|
-
throw new TestRunnerError({
|
|
113
|
-
message: `Vitest is not installed in "${projectDir}"`,
|
|
114
|
-
cause,
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
const metadata = Schema.decodeUnknownOption(PackageMetadataSchema)(require(packageJson));
|
|
118
|
-
if (Option.isNone(metadata) ||
|
|
119
|
-
!isSupportedVitestVersion(metadata.value.version)) {
|
|
120
|
-
throw new TestRunnerError({
|
|
121
|
-
message: `Laymos requires Vitest >=4.1.10 <5`,
|
|
122
|
-
cause: Option.getOrUndefined(metadata)?.version,
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
return import(pathToFileURL(entrypoint).href);
|
|
126
|
-
}
|
|
127
|
-
function isSupportedVitestVersion(version) {
|
|
128
|
-
const [major = 0, minor = 0, patch = 0] = version
|
|
129
|
-
.split('.', 3)
|
|
130
|
-
.map((part) => Number.parseInt(part, 10));
|
|
131
|
-
if (major !== 4)
|
|
132
|
-
return false;
|
|
133
|
-
const [requiredMajor, requiredMinor, requiredPatch] = minimumVitestVersion;
|
|
134
|
-
return (major > requiredMajor ||
|
|
135
|
-
(major === requiredMajor &&
|
|
136
|
-
(minor > requiredMinor ||
|
|
137
|
-
(minor === requiredMinor && patch >= requiredPatch))));
|
|
138
|
-
}
|
|
139
|
-
function mapRunResult(projectDir, result, duration) {
|
|
140
|
-
const modules = result.testModules.map((module) => mapModule(projectDir, module));
|
|
141
|
-
const unhandledErrors = result.unhandledErrors.map(mapError);
|
|
142
|
-
return {
|
|
143
|
-
status: unhandledErrors.length === 0 &&
|
|
144
|
-
modules.every(({ status }) => status !== 'failed')
|
|
145
|
-
? 'passed'
|
|
146
|
-
: 'failed',
|
|
147
|
-
duration,
|
|
148
|
-
modules,
|
|
149
|
-
unhandledErrors,
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
function mapModule(projectDir, module) {
|
|
153
|
-
const children = module.children.array();
|
|
154
|
-
const diagnostic = module.diagnostic();
|
|
155
|
-
return {
|
|
156
|
-
id: module.id,
|
|
157
|
-
name: module.relativeModuleId,
|
|
158
|
-
path: normalizePath(relative(projectDir, module.moduleId)),
|
|
159
|
-
projectName: module.project.name,
|
|
160
|
-
status: normalizeStatus(module.state()),
|
|
161
|
-
duration: diagnostic.environmentSetupDuration +
|
|
162
|
-
diagnostic.prepareDuration +
|
|
163
|
-
diagnostic.collectDuration +
|
|
164
|
-
diagnostic.setupDuration +
|
|
165
|
-
diagnostic.duration,
|
|
166
|
-
suites: children
|
|
167
|
-
.filter((child) => child.type === 'suite')
|
|
168
|
-
.map(mapSuite),
|
|
169
|
-
cases: children
|
|
170
|
-
.filter((child) => child.type === 'test')
|
|
171
|
-
.map(mapCase),
|
|
172
|
-
errors: module.errors().map(mapError),
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
function mapSuite(suite) {
|
|
176
|
-
const children = suite.children.array();
|
|
177
|
-
const suites = children
|
|
178
|
-
.filter((child) => child.type === 'suite')
|
|
179
|
-
.map(mapSuite);
|
|
180
|
-
const cases = children
|
|
181
|
-
.filter((child) => child.type === 'test')
|
|
182
|
-
.map(mapCase);
|
|
183
|
-
return {
|
|
184
|
-
id: suite.id,
|
|
185
|
-
name: suite.name,
|
|
186
|
-
...suiteMetadata(suite),
|
|
187
|
-
status: normalizeStatus(suite.state()),
|
|
188
|
-
suites,
|
|
189
|
-
cases,
|
|
190
|
-
errors: suite.errors().map(mapError),
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
function suiteMetadata(suite) {
|
|
194
|
-
const metadata = Schema.decodeUnknownOption(LaymosSuiteMetaSchema)(suite.meta());
|
|
195
|
-
if (Option.isNone(metadata))
|
|
196
|
-
return {};
|
|
197
|
-
return {
|
|
198
|
-
description: metadata.value.laymosSuite.description,
|
|
199
|
-
...(metadata.value.laymosSuite.documentation === undefined
|
|
200
|
-
? {}
|
|
201
|
-
: { documentation: metadata.value.laymosSuite.documentation }),
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
function mapCase(testCase) {
|
|
205
|
-
const result = testCase.result();
|
|
206
|
-
const diagnostic = testCase.diagnostic();
|
|
207
|
-
const metadata = Schema.decodeUnknownOption(LaymosTaskMetaSchema)(testCase.meta());
|
|
208
|
-
const evidence = evidenceProperty(testCase.artifacts(), metadata);
|
|
209
|
-
const authored = Option.isSome(metadata) || evidence.evidence !== undefined;
|
|
210
|
-
const assertionFailed = evidence.evidence?.assertions.some(({ status }) => status === 'failed') ??
|
|
211
|
-
false;
|
|
212
|
-
const errors = (result.errors ?? [])
|
|
213
|
-
.map(mapError)
|
|
214
|
-
.filter(({ name }) => !assertionFailed || name !== 'LaymosAssertionFailures');
|
|
215
|
-
return {
|
|
216
|
-
id: testCase.id,
|
|
217
|
-
name: testCase.name,
|
|
218
|
-
fullName: testCase.fullName,
|
|
219
|
-
status: normalizeStatus(result.state),
|
|
220
|
-
duration: diagnostic?.duration ?? 0,
|
|
221
|
-
errors,
|
|
222
|
-
...(testCase.location === undefined
|
|
223
|
-
? {}
|
|
224
|
-
: {
|
|
225
|
-
location: {
|
|
226
|
-
line: testCase.location.line,
|
|
227
|
-
column: testCase.location.column,
|
|
228
|
-
},
|
|
229
|
-
}),
|
|
230
|
-
...(authored ? { authoredBy: 'laymos' } : {}),
|
|
231
|
-
...evidence,
|
|
232
|
-
};
|
|
233
|
-
}
|
|
234
|
-
function evidenceProperty(artifacts, metadata) {
|
|
235
|
-
const artifact = artifacts
|
|
236
|
-
.map((artifact) => Schema.decodeUnknownOption(LaymosTestArtifactSchema)(artifact))
|
|
237
|
-
.reverse()
|
|
238
|
-
.find(Option.isSome);
|
|
239
|
-
if (artifact !== undefined) {
|
|
240
|
-
return { evidence: artifact.value.evidence };
|
|
241
|
-
}
|
|
242
|
-
if (Option.isSome(metadata)) {
|
|
243
|
-
return {
|
|
244
|
-
evidence: {
|
|
245
|
-
description: metadata.value.laymosTest.description,
|
|
246
|
-
...(metadata.value.laymosTest.documentation === undefined
|
|
247
|
-
? {}
|
|
248
|
-
: { documentation: metadata.value.laymosTest.documentation }),
|
|
249
|
-
assertions: [],
|
|
250
|
-
},
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
return {};
|
|
254
|
-
}
|
|
255
|
-
function normalizeStatus(status) {
|
|
256
|
-
return status === 'queued' ? 'pending' : status;
|
|
257
|
-
}
|
|
258
|
-
export function mapError(error) {
|
|
259
|
-
const decoded = Schema.decodeUnknownOption(ErrorInputSchema)(error);
|
|
260
|
-
if (Option.isSome(decoded)) {
|
|
261
|
-
return {
|
|
262
|
-
name: decoded.value.name ?? 'Error',
|
|
263
|
-
message: decoded.value.message,
|
|
264
|
-
...(decoded.value.stack === undefined
|
|
265
|
-
? {}
|
|
266
|
-
: { stack: decoded.value.stack }),
|
|
267
|
-
...(decoded.value.expected === undefined
|
|
268
|
-
? {}
|
|
269
|
-
: { expected: decoded.value.expected }),
|
|
270
|
-
...(decoded.value.actual === undefined
|
|
271
|
-
? {}
|
|
272
|
-
: { actual: decoded.value.actual }),
|
|
273
|
-
...(decoded.value.diff === undefined ? {} : { diff: decoded.value.diff }),
|
|
274
|
-
};
|
|
275
|
-
}
|
|
276
|
-
return { name: 'Error', message: String(error) };
|
|
277
|
-
}
|
|
278
|
-
function normalizePath(path) {
|
|
279
|
-
return path.split(sep).join('/');
|
|
280
|
-
}
|
|
281
|
-
function errorMessage(cause) {
|
|
282
|
-
const decoded = Schema.decodeUnknownOption(ErrorInputSchema)(cause);
|
|
283
|
-
return Option.isSome(decoded) ? decoded.value.message : String(cause);
|
|
284
|
-
}
|