-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fixing typing issues with webpack 5 Proper fix gated by webpack/webpack#12869 Added unit tests Found issue with Logger not using `stderrConsole` when option was set to do so. * Fixing typing issues with webpack 5 Proper fix gated by webpack/webpack#12869 Added unit tests Found issue with Logger not using `stderrConsole` when option was set to do so. * Ran prettier manually
- Loading branch information
1 parent
ea0b4f9
commit 3e875f6
Showing
15 changed files
with
3,072 additions
and
1,660 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module.exports = { | ||
preset: "ts-jest", | ||
testEnvironment: "node", | ||
transform: { | ||
"^.+\\.[tj]sx?$": "ts-jest", | ||
}, | ||
moduleFileExtensions: ["ts", "tsx", "js", "jsx"], | ||
globals: { "ts-jest": { tsConfig: "<rootDir>/src/tsconfig.spec.json" } }, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { makeLogger } from "../logger"; | ||
import * as chalk from "chalk"; | ||
import { mockProcessStdout, mockProcessStderr } from "jest-mock-process"; | ||
|
||
// jest.mock("Console", () => { | ||
// return jest.fn(); | ||
// }); | ||
|
||
describe(`Logger`, () => { | ||
const mockStdout = mockProcessStdout(); | ||
const mockStderr = mockProcessStderr(); | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
test(`Can create a logger instance to process.stdout`, () => { | ||
const result = makeLogger( | ||
{ | ||
baseUrl: undefined, | ||
colors: false, | ||
configFile: "", | ||
context: undefined, | ||
extensions: [], | ||
logInfoToStdOut: true, | ||
logLevel: "INFO", | ||
mainFields: [], | ||
silent: false, | ||
}, | ||
new chalk.Instance() | ||
); | ||
expect(result).toBeDefined(); | ||
|
||
result.logInfo(`Test logInfo`); | ||
result.logWarning(`Test logWarning`); | ||
result.logError(`Test logError`); | ||
result.log(`Test external logger`); | ||
|
||
expect(mockStdout).toHaveBeenCalledTimes(2); | ||
expect(mockStderr).toHaveBeenCalledTimes(2); | ||
}); | ||
|
||
test(`Can create a logger instance to process.stderr`, () => { | ||
const result = makeLogger( | ||
{ | ||
baseUrl: undefined, | ||
colors: false, | ||
configFile: "", | ||
context: undefined, | ||
extensions: [], | ||
logInfoToStdOut: false, | ||
logLevel: "INFO", | ||
mainFields: [], | ||
silent: false, | ||
}, | ||
new chalk.Instance() | ||
); | ||
expect(result).toBeDefined(); | ||
|
||
result.log(`Test external logger`); | ||
|
||
expect(mockStderr).toHaveBeenCalledTimes(1); | ||
expect(mockStdout).not.toHaveBeenCalled(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import * as webpack from "webpack"; | ||
import { Configuration } from "webpack"; | ||
const path = require("path"); | ||
import { TsconfigPathsPlugin } from "../plugin"; | ||
|
||
describe(`TsconfigPathsPlugin`, () => { | ||
const SETTINGS: Configuration = { | ||
mode: "development", | ||
context: path.resolve(__dirname, "src"), | ||
entry: `../../../example/src/index.ts`, | ||
output: { | ||
path: path.join(__dirname, "../../temp"), | ||
filename: "bundle.js", | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\\.tsx?$/, | ||
exclude: /^node_modules/, | ||
loader: "ts-loader", | ||
options: { | ||
configFile: "./example/tsconfig.json", | ||
}, | ||
}, | ||
], | ||
}, | ||
resolve: { | ||
extensions: [".ts", ".tsx", ".js"], | ||
}, | ||
}; | ||
|
||
it(`Can initialize the plugin`, async (done) => { | ||
const testPlugin = new TsconfigPathsPlugin({ | ||
configFile: `${__dirname}/../../example/tsconfig.json`, | ||
logLevel: "INFO", | ||
extensions: [".ts", ".tsx"], | ||
mainFields: ["browser", "main"], | ||
}); | ||
expect(testPlugin).toBeInstanceOf(TsconfigPathsPlugin); | ||
|
||
const testSettings: webpack.Configuration = { | ||
...SETTINGS, | ||
resolve: { | ||
extensions: [".ts", ".tsx", ".js"], | ||
plugins: [testPlugin], | ||
}, | ||
}; | ||
|
||
const compiler = webpack(testSettings); | ||
|
||
compiler.run((err, stats) => { | ||
if (err) { | ||
done(err); | ||
return; | ||
} | ||
expect(stats).toBeDefined(); | ||
const details = stats?.toJson(); | ||
expect(details?.errorsCount).toEqual(0); | ||
// TODO There should probably be a test that verifies the stats match what is expected | ||
done(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.