yeoman-test 7.4.0 → 8.0.0-alpha.1
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/dist/helpers.d.ts +2 -2
- package/dist/helpers.js +5 -1
- package/dist/run-context.d.ts +5 -5
- package/dist/run-context.js +7 -7
- package/dist/run-result.d.ts +3 -3
- package/dist/run-result.js +3 -3
- package/dist/test-context.d.ts +1 -1
- package/dist/test-context.js +7 -0
- package/package.json +17 -16
package/dist/helpers.d.ts
CHANGED
|
@@ -149,6 +149,6 @@ export declare class YeomanTest {
|
|
|
149
149
|
*/
|
|
150
150
|
prepareTemporaryDir(settings?: RunContextSettings): BasicRunContext;
|
|
151
151
|
}
|
|
152
|
-
declare const
|
|
153
|
-
export default
|
|
152
|
+
declare const defaultHelpers: YeomanTest;
|
|
153
|
+
export default defaultHelpers;
|
|
154
154
|
export declare const createHelpers: (options: any) => YeomanTest;
|
package/dist/helpers.js
CHANGED
|
@@ -76,6 +76,9 @@ export class YeomanTest {
|
|
|
76
76
|
*/
|
|
77
77
|
mockPrompt(envOrGenerator, mockedAnswers, options) {
|
|
78
78
|
const environment = 'env' in envOrGenerator ? envOrGenerator.env : envOrGenerator;
|
|
79
|
+
if (!environment.adapter) {
|
|
80
|
+
throw new Error('environment is not an Environment instance');
|
|
81
|
+
}
|
|
79
82
|
const { promptModule } = environment.adapter;
|
|
80
83
|
for (const name of Object.keys(promptModule.prompts)) {
|
|
81
84
|
promptModule.registerPrompt(name, class CustomDummyPrompt extends DummyPrompt {
|
|
@@ -273,7 +276,8 @@ export class YeomanTest {
|
|
|
273
276
|
return context;
|
|
274
277
|
}
|
|
275
278
|
}
|
|
276
|
-
|
|
279
|
+
const defaultHelpers = new YeomanTest();
|
|
280
|
+
export default defaultHelpers;
|
|
277
281
|
export const createHelpers = options => {
|
|
278
282
|
const helpers = new YeomanTest();
|
|
279
283
|
Object.assign(helpers, options);
|
package/dist/run-context.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ import { EventEmitter } from 'node:events';
|
|
|
3
3
|
import type Generator from 'yeoman-generator';
|
|
4
4
|
import type Environment from 'yeoman-environment';
|
|
5
5
|
import { type LookupOptions, type Options } from 'yeoman-environment';
|
|
6
|
-
import MemFsEditor from 'mem-fs-editor';
|
|
7
|
-
import
|
|
6
|
+
import { type MemFsEditor, type VinylMemFsEditorFile } from 'mem-fs-editor';
|
|
7
|
+
import { type Store } from 'mem-fs';
|
|
8
8
|
import RunResult, { type RunResultOptions } from './run-result.js';
|
|
9
9
|
import { type GeneratorConstructor, type Dependency, type YeomanTest } from './helpers.js';
|
|
10
10
|
import { type DummyPromptOptions } from './adapter.js';
|
|
@@ -21,7 +21,7 @@ export type RunContextSettings = {
|
|
|
21
21
|
oldCwd?: string;
|
|
22
22
|
forwardCwd?: boolean;
|
|
23
23
|
autoCleanup?: boolean;
|
|
24
|
-
memFs?:
|
|
24
|
+
memFs?: Store;
|
|
25
25
|
/**
|
|
26
26
|
* File path to the generator (only used if Generator is a constructor)
|
|
27
27
|
*/
|
|
@@ -42,8 +42,8 @@ export declare class RunContextBase<GeneratorType extends Generator = Generator>
|
|
|
42
42
|
readonly envOptions: Environment.Options;
|
|
43
43
|
completed: boolean;
|
|
44
44
|
targetDirectory?: string;
|
|
45
|
-
editor: MemFsEditor
|
|
46
|
-
memFs:
|
|
45
|
+
editor: MemFsEditor;
|
|
46
|
+
memFs: Store<VinylMemFsEditorFile>;
|
|
47
47
|
mockedGeneratorFactory: MockedGeneratorFactory;
|
|
48
48
|
protected environmentPromise?: PromiseRunResult<GeneratorType>;
|
|
49
49
|
private args;
|
package/dist/run-context.js
CHANGED
|
@@ -6,9 +6,10 @@ import { EventEmitter } from 'node:events';
|
|
|
6
6
|
import process from 'node:process';
|
|
7
7
|
import _ from 'lodash';
|
|
8
8
|
import tempDirectory from 'temp-dir';
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
import
|
|
9
|
+
import { create as createMemFsEditor } from 'mem-fs-editor';
|
|
10
|
+
// eslint-disable-next-line n/file-extension-in-import
|
|
11
|
+
import { resetFileCommitStates } from 'mem-fs-editor/state';
|
|
12
|
+
import { create as createMemFs } from 'mem-fs';
|
|
12
13
|
import RunResult from './run-result.js';
|
|
13
14
|
import defaultHelpers from './helpers.js';
|
|
14
15
|
import testContext from './test-context.js';
|
|
@@ -69,7 +70,7 @@ export class RunContextBase extends EventEmitter {
|
|
|
69
70
|
this.cd(this.settings.cwd);
|
|
70
71
|
}
|
|
71
72
|
this.helpers = helpers;
|
|
72
|
-
this.memFs = settings?.memFs ??
|
|
73
|
+
this.memFs = settings?.memFs ?? createMemFs();
|
|
73
74
|
this.mockedGeneratorFactory = this.helpers.createMockedGenerator;
|
|
74
75
|
}
|
|
75
76
|
/**
|
|
@@ -451,11 +452,10 @@ export class RunContextBase extends EventEmitter {
|
|
|
451
452
|
}
|
|
452
453
|
if (!this.keepFsState) {
|
|
453
454
|
this.memFs.each(file => {
|
|
454
|
-
|
|
455
|
-
delete file[MemFsEditorState.STATE_CLEARED];
|
|
455
|
+
resetFileCommitStates(file);
|
|
456
456
|
});
|
|
457
457
|
}
|
|
458
|
-
this.editor =
|
|
458
|
+
this.editor = createMemFsEditor(this.memFs);
|
|
459
459
|
for (const onTargetDirectory of this.onTargetDirectoryCallbacks) {
|
|
460
460
|
// eslint-disable-next-line no-await-in-loop
|
|
461
461
|
await onTargetDirectory.call(this, this.targetDirectory);
|
package/dist/run-result.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { type MemFsEditor } from 'mem-fs-editor';
|
|
2
2
|
import type { Store } from 'mem-fs';
|
|
3
3
|
import type Environment from 'yeoman-environment';
|
|
4
4
|
import type Generator from 'yeoman-generator';
|
|
@@ -26,7 +26,7 @@ export type RunResultOptions<GeneratorType extends Generator> = {
|
|
|
26
26
|
* The file-system of the generator.
|
|
27
27
|
*/
|
|
28
28
|
memFs: Store;
|
|
29
|
-
fs?: MemFsEditor
|
|
29
|
+
fs?: MemFsEditor;
|
|
30
30
|
/**
|
|
31
31
|
* The mocked generators of the context.
|
|
32
32
|
*/
|
|
@@ -43,7 +43,7 @@ export default class RunResult<GeneratorType extends Generator = Generator> {
|
|
|
43
43
|
cwd: string;
|
|
44
44
|
oldCwd: string;
|
|
45
45
|
memFs: Store;
|
|
46
|
-
fs:
|
|
46
|
+
fs: MemFsEditor;
|
|
47
47
|
mockedGenerators: any;
|
|
48
48
|
options: RunResultOptions<GeneratorType>;
|
|
49
49
|
constructor(options: RunResultOptions<GeneratorType>);
|
package/dist/run-result.js
CHANGED
|
@@ -2,7 +2,7 @@ import assert from 'node:assert';
|
|
|
2
2
|
import { existsSync, readFileSync, rmSync } from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import process from 'node:process';
|
|
5
|
-
import
|
|
5
|
+
import { create as createMemFsEditor } from 'mem-fs-editor';
|
|
6
6
|
const isObject = object => typeof object === 'object' && object !== null && object !== undefined;
|
|
7
7
|
function convertArgs(args) {
|
|
8
8
|
if (args.length > 1) {
|
|
@@ -32,7 +32,7 @@ export default class RunResult {
|
|
|
32
32
|
this.cwd = options.cwd ?? process.cwd();
|
|
33
33
|
this.oldCwd = options.oldCwd;
|
|
34
34
|
this.memFs = options.memFs;
|
|
35
|
-
this.fs = this.memFs &&
|
|
35
|
+
this.fs = this.memFs && createMemFsEditor(this.memFs);
|
|
36
36
|
this.mockedGenerators = options.mockedGenerators || {};
|
|
37
37
|
this.options = options;
|
|
38
38
|
}
|
|
@@ -121,7 +121,7 @@ export default class RunResult {
|
|
|
121
121
|
}
|
|
122
122
|
_readFile(filename, json) {
|
|
123
123
|
filename = this._fileName(filename);
|
|
124
|
-
const file = this.fs ? this.fs.read(filename) : readFileSync(filename, 'utf8');
|
|
124
|
+
const file = (this.fs ? this.fs.read(filename) : undefined) ?? readFileSync(filename, 'utf8');
|
|
125
125
|
return json ? JSON.parse(file) : file;
|
|
126
126
|
}
|
|
127
127
|
_exists(filename) {
|
package/dist/test-context.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type RunResult from './run-result.js';
|
|
|
3
3
|
declare class TestContext {
|
|
4
4
|
runResult?: RunResult;
|
|
5
5
|
private runContext?;
|
|
6
|
-
startNewContext(runContext
|
|
6
|
+
startNewContext(runContext?: RunContext<any>): void;
|
|
7
7
|
}
|
|
8
8
|
declare const testContext: TestContext;
|
|
9
9
|
export default testContext;
|
package/dist/test-context.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import process from 'node:process';
|
|
1
2
|
class TestContext {
|
|
2
3
|
runResult;
|
|
3
4
|
runContext;
|
|
@@ -8,6 +9,12 @@ class TestContext {
|
|
|
8
9
|
}
|
|
9
10
|
}
|
|
10
11
|
const testContext = new TestContext();
|
|
12
|
+
const cleanupTemporaryDir = () => {
|
|
13
|
+
testContext.startNewContext();
|
|
14
|
+
};
|
|
15
|
+
process.on('exit', cleanupTemporaryDir);
|
|
16
|
+
process.on('SIGINT', cleanupTemporaryDir);
|
|
17
|
+
process.on('SIGTERM', cleanupTemporaryDir);
|
|
11
18
|
export default testContext;
|
|
12
19
|
const handler2 = {
|
|
13
20
|
get(_target, prop, receiver) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yeoman-test",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.0-alpha.1",
|
|
4
4
|
"description": "Test utilities for Yeoman generators",
|
|
5
5
|
"homepage": "http://yeoman.io/authoring/testing.html",
|
|
6
6
|
"author": "The Yeoman Team",
|
|
@@ -20,48 +20,44 @@
|
|
|
20
20
|
"repository": "yeoman/yeoman-test",
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"engines": {
|
|
23
|
-
"node": "^
|
|
23
|
+
"node": "^16.17.0 || >=18.12.0"
|
|
24
24
|
},
|
|
25
25
|
"config": {
|
|
26
26
|
"doc_path": "../yeoman-test-doc"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@node
|
|
30
|
-
"@types/mocha": "^10.0.0",
|
|
29
|
+
"@types/node": "^16.18.19",
|
|
31
30
|
"@types/sinon": "^10.0.13",
|
|
31
|
+
"c8": "^7.13.0",
|
|
32
32
|
"coveralls": "^3.1.1",
|
|
33
|
+
"esmocha": "^0.1.4",
|
|
33
34
|
"husky": "^8.0.2",
|
|
34
35
|
"jsdoc": "^3.6.10",
|
|
35
36
|
"lint-staged": "^13.0.3",
|
|
36
|
-
"mem-fs": "^2.2.1",
|
|
37
|
-
"mocha": "^10.1.0",
|
|
38
|
-
"mocha-expect-snapshot": "^7.0.0",
|
|
39
37
|
"prettier": "^2.2.1",
|
|
40
38
|
"prettier-plugin-packagejson": "^2.3.0",
|
|
41
39
|
"tui-jsdoc-template": "^1.2.2",
|
|
42
40
|
"typescript": "^4.9.3",
|
|
43
41
|
"xo": "^0.53.1",
|
|
44
|
-
"yeoman-environment": "^
|
|
45
|
-
"yeoman-generator": "^5.7.0"
|
|
42
|
+
"yeoman-environment": "^4.0.0-alpha.1"
|
|
46
43
|
},
|
|
47
44
|
"dependencies": {
|
|
48
45
|
"@types/inquirer": "^8.2.5",
|
|
49
|
-
"@types/mem-fs-editor": "^7.0.2",
|
|
50
46
|
"@types/yeoman-environment": "^2.10.8",
|
|
51
47
|
"@types/yeoman-generator": "^5.2.11",
|
|
52
48
|
"inquirer": "^8.2.5",
|
|
53
49
|
"lodash": "^4.17.21",
|
|
54
|
-
"mem-fs
|
|
50
|
+
"mem-fs": "^3.0.0",
|
|
51
|
+
"mem-fs-editor": "^10.0.1",
|
|
55
52
|
"sinon": "^14.0.2",
|
|
56
|
-
"temp-dir": "^3.0.0"
|
|
53
|
+
"temp-dir": "^3.0.0",
|
|
54
|
+
"yeoman-generator": "^5.7.0"
|
|
57
55
|
},
|
|
58
56
|
"peerDependencies": {
|
|
59
|
-
"
|
|
60
|
-
"yeoman-environment": "^3.13.0",
|
|
61
|
-
"yeoman-generator": "*"
|
|
57
|
+
"yeoman-environment": "^3.13.0 || ^4.0.0-alpha.0"
|
|
62
58
|
},
|
|
63
59
|
"scripts": {
|
|
64
|
-
"test": "
|
|
60
|
+
"test": "c8 esmocha",
|
|
65
61
|
"build": "tsc",
|
|
66
62
|
"prepare": "npm run build",
|
|
67
63
|
"pretest": "xo",
|
|
@@ -86,5 +82,10 @@
|
|
|
86
82
|
"prettier --write",
|
|
87
83
|
"git add"
|
|
88
84
|
]
|
|
85
|
+
},
|
|
86
|
+
"overrides": {
|
|
87
|
+
"yeoman-generator": {
|
|
88
|
+
"yeoman-environment": "^4.0.0-alpha.0"
|
|
89
|
+
}
|
|
89
90
|
}
|
|
90
91
|
}
|