Skip to content

Commit dfcf69b

Browse files
tobiasquecknlunets
andauthored
Type augmentation for mem-fs-editor (#815)
* trying to outsource type fixes * better? * use new types for tests * besser * better text * use enhanced mem-fs-editor type everywhere Co-authored-by: Nicolas Lunet <nicolas.lunet@sap.com>
1 parent b20b199 commit dfcf69b

29 files changed

+108
-58
lines changed

packages/fe-fpm-writer/test/integration/index.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ describe('use FPM with existing apps', () => {
246246

247247
afterAll(() => {
248248
expect(
249-
(fs as any).dump(testOutput, '**/test-output/**/webapp/{manifest.json,Component.ts,ext/**/*}')
249+
fs.dump(testOutput, '**/test-output/**/webapp/{manifest.json,Component.ts,ext/**/*}')
250250
).toMatchSnapshot();
251251
});
252252
});

packages/fe-fpm-writer/test/unit/building-block.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ describe('Building Blocks', () => {
215215
},
216216
fs
217217
);
218-
expect((fs as any).dump(testAppPath)).toMatchSnapshot(
218+
expect(fs.dump(testAppPath)).toMatchSnapshot(
219219
`generate-${testData.buildingBlockData.buildingBlockType}-with-id-no-macros-ns`
220220
);
221221
await writeFilesForDebugging(fs);
@@ -260,7 +260,7 @@ describe('Building Blocks', () => {
260260
},
261261
fs
262262
);
263-
expect((fs as any).dump(testAppPath)).toMatchSnapshot(
263+
expect(fs.dump(testAppPath)).toMatchSnapshot(
264264
`generate-${testData.buildingBlockData.buildingBlockType}-with-id`
265265
);
266266
await writeFilesForDebugging(fs);
@@ -323,7 +323,7 @@ describe('Building Blocks', () => {
323323
},
324324
fs
325325
);
326-
expect((fs as any).dump(testAppPath)).toMatchSnapshot(
326+
expect(fs.dump(testAppPath)).toMatchSnapshot(
327327
`generate-${testData.buildingBlockData.buildingBlockType}-with-optional-params`
328328
);
329329
await writeFilesForDebugging(fs);

packages/fe-fpm-writer/tsconfig.json

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
{
22
"extends": "../../tsconfig.json",
3-
"include": ["src", "src/**/*.json"],
3+
"include": [
4+
"../../types/mem-fs-editor.d.ts",
5+
"src",
6+
"src/**/*.json"
7+
],
48
"compilerOptions": {
59
"rootDir": "src",
610
"outDir": "dist"
711
},
8-
"references": [
9-
{ "path": "../project-access" }
10-
]
11-
}
12+
"references": [{ "path": "../project-access" }]
13+
}

packages/fiori-elements-writer/test/alp.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ describe(`Fiori Elements template: ${TEST_NAME}`, () => {
8686
test.each(alpConfigs)('Generate files for template: $name', async ({ name, config }) => {
8787
const testPath = join(curTestOutPath, name);
8888
const fs = await generate(testPath, config);
89-
expect((fs as any).dump(testPath)).toMatchSnapshot();
89+
expect(fs.dump(testPath)).toMatchSnapshot();
9090

9191
return new Promise((resolve) => {
9292
// write out the files for debugging

packages/fiori-elements-writer/test/feop.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ describe(`Fiori Elements template: ${TEST_NAME}`, () => {
4747
test.each(feopConfigs)('Generate files for template: $name', async ({ name, config }) => {
4848
const testPath = join(curTestOutPath, name);
4949
const fs = await generate(testPath, config);
50-
expect((fs as any).dump(testPath)).toMatchSnapshot();
50+
expect(fs.dump(testPath)).toMatchSnapshot();
5151

5252
return new Promise((resolve) => {
5353
// write out the files for debugging

packages/fiori-elements-writer/test/fpm.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ describe(`Flexible Programming Model template: ${TEST_NAME}`, () => {
5555
test.each(fpmConfigs)('Generate files for template: $name', async ({ name, config }) => {
5656
const testPath = join(curTestOutPath, name);
5757
const fs = await generate(testPath, config);
58-
expect((fs as any).dump(testPath)).toMatchSnapshot();
58+
expect(fs.dump(testPath)).toMatchSnapshot();
5959

6060
return new Promise((resolve) => {
6161
// write out the files for debugging

packages/fiori-elements-writer/test/lrop.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ describe(`Fiori Elements template: ${TEST_NAME}`, () => {
179179
test.each(lropConfigs)('Generate files for template: $name', async ({ name, config }) => {
180180
const testPath = join(curTestOutPath, name);
181181
const fs = await generate(testPath, config);
182-
expect((fs as any).dump(testPath)).toMatchSnapshot();
182+
expect(fs.dump(testPath)).toMatchSnapshot();
183183

184184
return new Promise((resolve) => {
185185
// write out the files for debugging

packages/fiori-elements-writer/test/ovp.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ describe(`Fiori Elements template: ${TEST_NAME}`, () => {
7171
test.each(configuration)('Generate files for template: $name', async ({ name, config }) => {
7272
const testPath = join(curTestOutPath, name);
7373
const fs = await generate(testPath, config);
74-
expect((fs as any).dump(testPath)).toMatchSnapshot();
74+
expect(fs.dump(testPath)).toMatchSnapshot();
7575

7676
return new Promise((resolve) => {
7777
// write out the files for debugging

packages/fiori-elements-writer/test/worklist.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ describe(`Fiori Elements template: ${TEST_NAME}`, () => {
5656
test.each(configuration)('Generate files for template: $name', async ({ name, config }) => {
5757
const testPath = join(curTestOutPath, name);
5858
const fs = await generate(testPath, config);
59-
expect((fs as any).dump(testPath)).toMatchSnapshot();
59+
expect(fs.dump(testPath)).toMatchSnapshot();
6060

6161
return new Promise((resolve) => {
6262
// write out the files for debugging

packages/fiori-elements-writer/tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"extends": "../../tsconfig.json",
33
"include": [
4+
"../../types/mem-fs-editor.d.ts",
45
"src",
56
"src/**/*.json"
67
],

packages/fiori-freestyle-writer/test/basic.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ describe(`Fiori freestyle template: ${TEST_NAME}`, () => {
119119
config.template.settings = settings;
120120
const testPath = join(curTestOutPath, name);
121121
const fs = await generate(testPath, config);
122-
expect((fs as any).dump(testPath)).toMatchSnapshot();
122+
expect(fs.dump(testPath)).toMatchSnapshot();
123123

124124
return new Promise((resolve) => {
125125
// write out the files for debugging

packages/fiori-freestyle-writer/test/index.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ describe(`Fiori freestyle templates: ${TEST_NAME}`, () => {
103103
test.each(configuration)('Generate files for template: $name', async ({ name, config }) => {
104104
const testPath = join(curTestOutPath, name);
105105
const fs = await generate(testPath, config);
106-
expect((fs as any).dump(testPath)).toMatchSnapshot();
106+
expect(fs.dump(testPath)).toMatchSnapshot();
107107
return new Promise((resolve) => {
108108
// write out the files for debugging
109109
if (debug?.enabled) {

packages/fiori-freestyle-writer/test/listdetail.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ describe(`Fiori freestyle template: ${TEST_NAME}`, () => {
6363
test.each(configuration)('Generate files for template: $name', async ({ name, config }) => {
6464
const testPath = join(curTestOutPath, name);
6565
const fs = await generate(join(testPath), config);
66-
expect((fs as any).dump(testPath)).toMatchSnapshot();
66+
expect(fs.dump(testPath)).toMatchSnapshot();
6767
return new Promise((resolve) => {
6868
// write out the files for debugging
6969
if (debug?.enabled) {

packages/fiori-freestyle-writer/test/worklist.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ describe(`Fiori freestyle template: ${TEST_NAME}`, () => {
156156
test.each(configuration)('Generate files for template: $name', async ({ name, config }) => {
157157
const testPath = join(curTestOutPath, name);
158158
const fs = await generate(testPath, config);
159-
expect((fs as any).dump(testPath)).toMatchSnapshot();
159+
expect(fs.dump(testPath)).toMatchSnapshot();
160160
return new Promise((resolve) => {
161161
// write out the files for debugging
162162
if (debug?.enabled) {

packages/fiori-freestyle-writer/tsconfig.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
{
22
"extends": "../../tsconfig.json",
3-
"include": ["src", "src/**/*.json"],
3+
"include": [
4+
"../../types/mem-fs-editor.d.ts",
5+
"src",
6+
"src/**/*.json"
7+
],
48
"compilerOptions": {
59
"rootDir": "src",
610
"outDir": "dist"

packages/odata-service-writer/test/index.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ describe('ODataService templates', () => {
6767
it('generate: valid project with standard valid input', async () => {
6868
const testDir = await createTestDir('odata-service-v2');
6969
await generate(testDir, validServiceConfig as OdataService, fs);
70-
expect((fs as any).dump(testDir)).toMatchSnapshot();
70+
expect(fs.dump(testDir)).toMatchSnapshot();
7171
});
7272

7373
it('generate: project with local annotations', async () => {
@@ -84,6 +84,6 @@ describe('ODataService templates', () => {
8484

8585
const testDir = await createTestDir('local-annotations');
8686
await generate(testDir, serviceConfigWithAnnotations, fs);
87-
expect((fs as any).dump(testDir)).toMatchSnapshot();
87+
expect(fs.dump(testDir)).toMatchSnapshot();
8888
});
8989
});

packages/odata-service-writer/tsconfig.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
{
22
"extends": "../../tsconfig.json",
3-
"include": ["src", "src/**/*.json"],
3+
"include": [
4+
"../../types/mem-fs-editor.d.ts",
5+
"src",
6+
"src/**/*.json"
7+
],
48
"compilerOptions": {
59
"rootDir": "src",
610
"outDir": "dist",

packages/project-access/src/file/file-search.ts

-17
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,6 @@ import { basename, dirname, join, sep } from 'path';
33
import { default as find } from 'findit2';
44
import { fileExists } from './file-access';
55

6-
/**
7-
* Add missing dump function declaration as mem-fs-editor types do not expose this.
8-
*/
9-
declare module 'mem-fs-editor' {
10-
type FileMap = { [key: string]: { state: 'modified' | 'deleted' } };
11-
12-
export interface Editor {
13-
/**
14-
* Dump files to compare expected result. Provide a cwd for relative path.
15-
* See also https://github.com/SBoudrias/mem-fs-editor#dumpcwd-filter for further details.
16-
*
17-
* @param [cwd] - optional, relative path
18-
*/
19-
dump(cwd?: string): FileMap;
20-
}
21-
}
22-
236
/**
247
* Creates a filter function that removes files that have been deleted in an instance of a mem-fs-editor.
258
*

packages/project-access/tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"extends": "../../tsconfig.json",
33
"include": [
4+
"../../types/mem-fs-editor.d.ts",
45
"src"
56
],
67
"compilerOptions": {

packages/ui5-application-writer/test/index.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ describe('UI5 templates', () => {
4646
it('generates files correctly', async () => {
4747
let projectDir = join(outputDir, 'testapp-simple');
4848
await generate(projectDir, ui5AppConfig, fs);
49-
expect((fs as any).dump(projectDir)).toMatchSnapshot();
49+
expect(fs.dump(projectDir)).toMatchSnapshot();
5050

5151
// Test `sap.app.sourceTemplate.toolsId` is correctly written
5252
ui5AppConfig.app.sourceTemplate = {

packages/ui5-application-writer/test/options.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe('UI5 templates', () => {
3131
sapux: true
3232
}
3333
});
34-
expect((fs as any).dump(projectDir)).toMatchSnapshot();
34+
expect(fs.dump(projectDir)).toMatchSnapshot();
3535
return new Promise((resolve) => {
3636
// write out the files for debugging
3737
if (debug) {
@@ -50,7 +50,7 @@ describe('UI5 templates', () => {
5050
loadReuseLibs: true
5151
}
5252
});
53-
expect((fs as any).dump(projectDir)).toMatchSnapshot();
53+
expect(fs.dump(projectDir)).toMatchSnapshot();
5454
return new Promise((resolve) => {
5555
// write out the files for debugging
5656
if (debug) {
@@ -72,7 +72,7 @@ describe('UI5 templates', () => {
7272
version: '1.92.1'
7373
}
7474
});
75-
expect((fs as any).dump(projectDir)).toMatchSnapshot();
75+
expect(fs.dump(projectDir)).toMatchSnapshot();
7676
return new Promise((resolve) => {
7777
// write out the files for debugging
7878
if (debug) {
@@ -95,7 +95,7 @@ describe('UI5 templates', () => {
9595
}
9696
})
9797
);
98-
expect((fs as any).dump(projectDir)).toMatchSnapshot();
98+
expect(fs.dump(projectDir)).toMatchSnapshot();
9999
return new Promise((resolve) => {
100100
// write out the files for debugging
101101
if (debug) {

packages/ui5-application-writer/tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"extends": "../../tsconfig.json",
33
"include": [
4+
"../../types/mem-fs-editor.d.ts",
45
"src",
56
"src/**/*.json"
67
],

packages/ui5-test-writer/test/integration/index.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,6 @@ describe('ui5-test-writer - Integration tests', () => {
9191
);
9292
fs = await generatePageObjectFile(projectDir, { targetKey: 'EmployeesCustomPage' }, fs);
9393

94-
expect((fs as any).dump(projectDir)).toMatchSnapshot();
94+
expect(fs.dump(projectDir)).toMatchSnapshot();
9595
});
9696
});

packages/ui5-test-writer/test/unit/index.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ describe('ui5-test-writer', () => {
8080
it.each(testPages)('$description', async (config) => {
8181
const projectDir = prepareTestFiles('Pages');
8282
fs = await generatePageObjectFile(projectDir, { targetKey: config.targetKey }, fs);
83-
expect((fs as any).dump(projectDir)).toMatchSnapshot();
83+
expect(fs.dump(projectDir)).toMatchSnapshot();
8484
});
8585

8686
it.each(testUnsupportedPages)('$description', async (config) => {
@@ -114,7 +114,7 @@ describe('ui5-test-writer', () => {
114114
{ targetKey: 'EmployeesListTarget', appID: 'test.ui5-test-writer' },
115115
fs
116116
);
117-
expect((fs as any).dump(projectDir)).toMatchSnapshot();
117+
expect(fs.dump(projectDir)).toMatchSnapshot();
118118
});
119119
});
120120

@@ -165,7 +165,7 @@ describe('ui5-test-writer', () => {
165165
it.each(testApplications)('$description', async (config) => {
166166
const projectDir = prepareTestFiles(config.dirPath);
167167
fs = await generateOPAFiles(projectDir, { scriptName: config.scriptName }, fs);
168-
expect((fs as any).dump(projectDir)).toMatchSnapshot();
168+
expect(fs.dump(projectDir)).toMatchSnapshot();
169169
});
170170

171171
it('No manifest', async () => {
@@ -195,7 +195,7 @@ describe('ui5-test-writer', () => {
195195
it('Providing an app ID', async () => {
196196
const projectDir = prepareTestFiles('MissingAppId');
197197
fs = await generateOPAFiles(projectDir, { appID: 'test.ui5-test-writer' }, fs);
198-
expect((fs as any).dump(projectDir)).toMatchSnapshot();
198+
expect(fs.dump(projectDir)).toMatchSnapshot();
199199
});
200200

201201
it('Freestyle app not supported', async () => {

packages/ui5-test-writer/tsconfig.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
{
22
"extends": "../../tsconfig.json",
3-
"include": ["src", "src/**/*.json"],
3+
"include": [
4+
"../../types/mem-fs-editor.d.ts",
5+
"src",
6+
"src/**/*.json"
7+
],
48
"compilerOptions": {
59
"rootDir": "src",
610
"outDir": "dist"

0 commit comments

Comments
 (0)