Skip to content

Commit 9fb6200

Browse files
committed
fix: linter, used built in logger, tests
1 parent 53e9583 commit 9fb6200

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

app-config-webpack/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"@app-config/config": "^2.8.7",
3535
"@app-config/schema": "^2.8.7",
3636
"@app-config/utils": "^2.8.7",
37+
"@app-config/logging": "^2.8.7",
3738
"loader-utils": "2"
3839
},
3940
"peerDependencies": {

app-config-webpack/src/index.test.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { resolve, join } from 'path';
2-
import webpack, { Compiler } from 'webpack';
2+
import webpack from 'webpack';
33
import HtmlPlugin from 'html-webpack-plugin';
4+
import { logger, LogLevel } from '@app-config/logging';
45
import AppConfigPlugin, { regex, loader, Options } from './index';
56

67
const examplesDir = resolve(__dirname, '../../examples');
@@ -54,7 +55,9 @@ describe('frontend-webpack-project example', () => {
5455
throw new Error('html-webpack-plugin not found');
5556
});
5657

57-
const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation();
58+
const writeMsg = jest.fn();
59+
logger.setWriter(writeMsg);
60+
logger.setLevel(LogLevel.Verbose);
5861

5962
try {
6063
await new Promise<void>((done, reject) => {
@@ -66,14 +69,16 @@ describe('frontend-webpack-project example', () => {
6669
});
6770
});
6871
} catch (err) {
69-
expect(consoleErrorSpy).toHaveBeenCalledTimes(3);
70-
expect(consoleErrorSpy).toHaveBeenCalledWith('html-webpack-plugin not found');
71-
expect(consoleErrorSpy).toHaveBeenCalledWith('Failed to resolve html-webpack-plugin');
72-
expect(consoleErrorSpy).toHaveBeenCalledWith(
73-
'Either include the module in your dependencies and enable the webpack plugin, or set headerInjection to false in your configuration.',
72+
expect(writeMsg).toHaveBeenCalledTimes(3);
73+
expect(writeMsg).toHaveBeenCalledWith(
74+
'[app-config][ERROR] html-webpack-plugin not found\n',
75+
);
76+
expect(writeMsg).toHaveBeenCalledWith(
77+
'[app-config][ERROR] Failed to resolve html-webpack-plugin\n',
78+
);
79+
expect(writeMsg).toHaveBeenCalledWith(
80+
'[app-config][ERROR] Either include the module in your dependencies and enable the webpack plugin, or set headerInjection to false in your configuration.\n',
7481
);
75-
} finally {
76-
consoleErrorSpy.mockRestore();
7782
}
7883
});
7984
});

app-config-webpack/src/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { join } from 'path';
22
import { Compiler } from 'webpack';
33
import type { ConfigLoadingOptions, SchemaLoadingOptions } from '@app-config/main';
44
import type { HtmlTagObject } from 'html-webpack-plugin';
5+
import { logger } from '@app-config/logging';
56

67
import { regex } from './loader';
78

@@ -114,10 +115,10 @@ export default class AppConfigPlugin implements Options {
114115
},
115116
);
116117
})
117-
.catch((error) => {
118-
console.error(error.message);
119-
console.error('Failed to resolve html-webpack-plugin');
120-
console.error(
118+
.catch((error: Error) => {
119+
logger.error(error.message);
120+
logger.error('Failed to resolve html-webpack-plugin');
121+
logger.error(
121122
'Either include the module in your dependencies and enable the webpack plugin, or set headerInjection to false in your configuration.',
122123
);
123124
});

0 commit comments

Comments
 (0)