Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate @storybook/node-logger to TypeScript #5153

Merged
merged 1 commit into from
Jan 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/node-logger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"license": "MIT",
"main": "dist/index.js",
"jsnext:main": "src/index.js",
"types": "dist/index.d.ts",
"scripts": {
"prepare": "node ../../scripts/prepare.js"
},
Expand All @@ -26,6 +26,10 @@
"pretty-hrtime": "^1.0.3",
"regenerator-runtime": "^0.12.1"
},
"devDependencies": {
"@types/npmlog": "^4.1.1",
"@types/pretty-hrtime": "^1.0.0"
},
"publishConfig": {
"access": "public"
}
Expand Down
31 changes: 0 additions & 31 deletions lib/node-logger/src/index.test.js

This file was deleted.

34 changes: 34 additions & 0 deletions lib/node-logger/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { info, warn, error } from 'npmlog';
import { logger } from '.';

jest.mock('npmlog', () => ({
info: jest.fn(),
warn: jest.fn(),
error: jest.fn(),
}));

describe('node-logger', () => {
beforeEach(() => {
// This feels odd but TypeScript doesn't understand that the imported
// npmlog module is being wrapped by Jest so we are type casting here
// in order to be allowed to call Jest's mockReset() method.
((info as any) as jest.MockInstance<any>).mockReset();
((warn as any) as jest.MockInstance<any>).mockReset();
((error as any) as jest.MockInstance<any>).mockReset();
});
it('should have an info method', () => {
const message = 'information';
logger.info(message);
expect(info).toHaveBeenCalledWith('', message);
});
it('should have a warn method', () => {
const message = 'warning message';
logger.warn(message);
expect(warn).toHaveBeenCalledWith('', message);
});
it('should have an error method', () => {
const message = 'error message';
logger.error(message);
expect(error).toHaveBeenCalledWith('', message);
});
});
9 changes: 5 additions & 4 deletions lib/node-logger/src/index.js → lib/node-logger/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ export const colors = {
};

export const logger = {
info: message => npmLog.info('', message),
warn: message => npmLog.warn('', message),
error: message => npmLog.error('', message),
trace: ({ message, time }) => npmLog.info(`${message} (${colors.purple(prettyTime(time))})`),
info: (message: string): void => npmLog.info('', message),
warn: (message: string): void => npmLog.warn('', message),
error: (message: string): void => npmLog.error('', message),
trace: ({ message, time }: { message: string; time: [number, number] }): void =>
npmLog.info('', `${message} (${colors.purple(prettyTime(time))})`),
};
8 changes: 8 additions & 0 deletions lib/node-logger/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": "./src"
},
"include": ["src/**/*"],
"exclude": ["src/**.test.ts"]
}
10 changes: 10 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2369,13 +2369,23 @@
resolved "https://registry.yarnpkg.com/@types/node/-/node-6.14.2.tgz#40b3dbb1221c7d66802cbcc32fe3b85e54569c77"
integrity sha512-JWB3xaVfsfnFY8Ofc9rTB/op0fqqTSqy4vBcVk1LuRJvta7KTX+D//fCkiTMeLGhdr2EbFZzQjC97gvmPilk9Q==

"@types/npmlog@^4.1.1":
version "4.1.1"
resolved "https://registry.yarnpkg.com/@types/npmlog/-/npmlog-4.1.1.tgz#b51cf39a6324a4ede17ef72dfa58a64fbefb39c7"
integrity sha512-uCZpakN0HrNsX+rZeXwCPByanpTN+dB3iApOrV4uggG955GZOw1YVziEpH6YDE60/+H95Jztg48UQ0NGZ6TPag==

"@types/parse5@^2.2.32":
version "2.2.34"
resolved "https://registry.yarnpkg.com/@types/parse5/-/parse5-2.2.34.tgz#e3870a10e82735a720f62d71dcd183ba78ef3a9d"
integrity sha1-44cKEOgnNacg9i1x3NGDunjvOp0=
dependencies:
"@types/node" "*"

"@types/pretty-hrtime@^1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@types/pretty-hrtime/-/pretty-hrtime-1.0.0.tgz#c5a2d644a135e988b2932f99737e67b3c62528d0"
integrity sha512-xl+5r2rcrxdLViAYkkiLMYsoUs3qEyrAnHFyEzYysgRxdVp3WbhysxIvJIxZp9FvZ2CYezh0TaHZorivH+voOQ==

"@types/prop-types@*", "@types/prop-types@^15.5.7":
version "15.5.8"
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.5.8.tgz#8ae4e0ea205fe95c3901a5a1df7f66495e3a56ce"
Expand Down