Skip to content

Commit

Permalink
Merge pull request #466 from zenn-dev/refactor-translate-test-to-japa…
Browse files Browse the repository at this point in the history
…nese

refactor: テストのタイトルを日本語に統一
  • Loading branch information
uttk-dev authored Sep 20, 2023
2 parents 21ae651 + cc761da commit 5e8fb3b
Show file tree
Hide file tree
Showing 17 changed files with 283 additions and 305 deletions.
6 changes: 3 additions & 3 deletions packages/zenn-cli/src/client/__tests__/lib/helper.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { encodeUrlPeriod, decodeUrlPeriod } from '../../lib/helper';

describe('pair of encodeUrlPeriod and decodeUrlPeriod', () => {
test('return original text `a.b.c` throgh encoding and decoding', () => {
describe('encodeUrlPeriod decodeUrlPeriod を使った処理のテスト', () => {
test('エンコードしてデコードすると元のテキスト"a.b.c"を返す', () => {
const original = 'a.b.c';
const encoded = encodeUrlPeriod(original);
expect(encoded).not.toContain('.');
const decoded = decodeUrlPeriod(encoded);
expect(decoded).toEqual(original);
});
test('return original text `2E.` throgh encoding and decoding', () => {
test('エンコードしてデコードすると元のテキスト"2E."を返す', () => {
const original = '2E.';
const encoded = encodeUrlPeriod(original);
expect(encoded).not.toContain('.');
Expand Down
20 changes: 10 additions & 10 deletions packages/zenn-cli/src/common/__tests__/helper.test.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,49 @@
import * as helper from '../helper';

describe('validateSlug', () => {
test('should return true with 12 valid characters', () => {
describe('validateSlug() のテスト', () => {
test('12文字の有効な文字列には true を返す', () => {
const result = helper.validateSlug('abcd-efg_123');
expect(result).toBe(true);
});

test('should return false with 12 invalid characters', () => {
test('12文字の無効な文字列には false を返す', () => {
expect(helper.validateSlug('abcd-efg%12')).toBe(false);
expect(helper.validateSlug('abcd-efg/12')).toBe(false);
expect(helper.validateSlug('abcd-efg"12')).toBe(false);
});

test('should return false with 11 valid characters', () => {
test('11文字の有効な文字列には false を返す', () => {
const result = helper.validateSlug('abcd-efg_12');
expect(result).toBe(false);
});

test('should return false with 50 valid characters', () => {
test('50文字の有効な文字列には false を返す', () => {
const result = helper.validateSlug(
'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx'
);
expect(result).toBe(true);
});

test('should return false with 51 valid characters', () => {
test('51文字の有効な文字列には false を返す', () => {
const result = helper.validateSlug(
'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxy'
);
expect(result).toBe(false);
});
});

describe('validateChapterSlug', () => {
test('should return true with 12 valid characters', () => {
describe('validateChapterSlug()のテスト', () => {
test('12文字の有効な文字列には true を返す', () => {
const result = helper.validateSlug('abcd-efg_123');
expect(result).toBe(true);
});

test('should return false with single valid character', () => {
test('1文字の有効な文字列には false を返す', () => {
const result = helper.validateSlug('a');
expect(result).toBe(false);
});

test('should return false with 51 valid characters', () => {
test('51文字の有効な文字列には false を返す', () => {
const result = helper.validateSlug(
'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxy'
);
Expand Down
4 changes: 2 additions & 2 deletions packages/zenn-cli/src/server/__tests__/commands/help.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { exec } from '../../commands/help';
import { commandListText } from '../../lib/messages';

describe('cli exec help', () => {
describe('helpコマンドのテスト', () => {
beforeEach(() => {
console.log = jest.fn();
});

test('should log help message', () => {
test('ヘルプメッセージを表示する', () => {
exec([]);
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining(commandListText)
Expand Down
12 changes: 6 additions & 6 deletions packages/zenn-cli/src/server/__tests__/commands/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { exec } from '../../commands/init';
import * as helper from '../../lib/helper';
import { initHelpText } from '../../lib/messages';

describe('cli exec init', () => {
describe('initコマンドのテスト', () => {
beforeEach(() => {
// mock
jest.spyOn(helper, 'generateFileIfNotExist').mockImplementation();
console.log = jest.fn();
console.error = jest.fn();
});

test('should call generateFileIfNotExist for directories', () => {
test('ディレクトリに対して generateFileIfNotExist を実行する', () => {
exec([]);
expect(helper.generateFileIfNotExist).toHaveBeenCalledWith(
expect.stringContaining(path.join(process.cwd(), 'articles/.keep')),
Expand All @@ -23,30 +23,30 @@ describe('cli exec init', () => {
);
});

test('should call generateFileIfNotExist for .gitignore', () => {
test('.gitignore に対して generateFileIfNotExist を実行する', () => {
exec([]);
expect(helper.generateFileIfNotExist).toHaveBeenCalledWith(
expect.stringContaining(path.join(process.cwd(), '.gitignore')),
expect.stringContaining(['node_modules', '.DS_Store'].join('\n'))
);
});

test('should call generateFileIfNotExist for README', () => {
test('README に対して generateFileIfNotExist を実行する', () => {
exec([]);
expect(helper.generateFileIfNotExist).toHaveBeenCalledWith(
expect.stringContaining(path.join(process.cwd(), 'README.md')),
expect.stringContaining('Zenn CLI')
);
});

test('should log success message', () => {
test('成功メッセージを表示する', () => {
exec([]);
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining('🎉 Done!')
);
});

test('should log help text with --help', () => {
test('--helpでもヘルプメッセージを表示する', () => {
exec(['--help']);
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining(initHelpText)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as helper from '../../lib/helper';
import * as Log from '../../lib/log';
import { newArticleHelpText } from '../../lib/messages';

describe('cli exec new:article', () => {
describe('new:articleコマンドのテスト', () => {
const expectedArticlesDirpath = path.join(process.cwd(), 'articles');

beforeEach(() => {
Expand All @@ -14,7 +14,7 @@ describe('cli exec new:article', () => {
console.log = jest.fn();
});

test('should call generateFileIfNotExist with proper arguments', () => {
test('有効な引数に generateFileIfNotExist を実行する', () => {
exec(['--emoji', '💭']);

expect(helper.generateFileIfNotExist).toHaveBeenCalledWith(
Expand All @@ -33,31 +33,31 @@ describe('cli exec new:article', () => {
);
});

test('should call generateFileIfNotExist with specified title', () => {
test('指定されたタイトルで generateFileIfNotExist を実行する', () => {
exec(['--title', 'A"B/C']);
expect(helper.generateFileIfNotExist).toHaveBeenCalledWith(
expect.stringContaining(expectedArticlesDirpath),
expect.stringContaining(`title: "A\\"B/C"`)
);
});

test('should call generateFileIfNotExist with specified published value true', () => {
test('`published: true` で generateFileIfNotExist を実行する', () => {
exec(['--published', 'true']);
expect(helper.generateFileIfNotExist).toHaveBeenCalledWith(
expect.stringContaining(expectedArticlesDirpath),
expect.stringContaining(`published: true`)
);
});

test('should call generateFileIfNotExist with specified published value false', () => {
test('`published: false` で generateFileIfNotExist を実行する', () => {
exec(['--published', 'false']);
expect(helper.generateFileIfNotExist).toHaveBeenCalledWith(
expect.stringContaining(expectedArticlesDirpath),
expect.stringContaining(`published: false`)
);
});

test('should call generateFileIfNotExist with the path including slug', () => {
test('指定した slug を含むパスで generateFileIfNotExist を実行する', () => {
const slug = 'example-article';
exec(['--slug', slug]);

Expand All @@ -67,32 +67,22 @@ describe('cli exec new:article', () => {
);
});

test('should call generateFileIfNotExist with the path including slug', () => {
const slug = 'example-article';
exec(['--slug', slug]);

expect(helper.generateFileIfNotExist).toHaveBeenCalledWith(
expect.stringMatching(`${expectedArticlesDirpath}/${slug}.md`),
expect.stringContaining(`---`)
);
});

test('should call generateFileIfNotExist with specified publication name', () => {
test('指定された Publication 名で generateFileIfNotExist を実行する', () => {
exec(['--publication-name', 'myPublication']);
expect(helper.generateFileIfNotExist).toHaveBeenCalledWith(
expect.stringContaining(expectedArticlesDirpath),
expect.stringContaining(`publication_name: myPublication`)
);
});

test('should log help text with --help', () => {
test('--help オプションを渡すとヘルプメッセージを表示する', () => {
exec(['--help']);
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining(newArticleHelpText)
);
});

test('should log error with invalid slug', () => {
test('無効な slug が渡されたらエラーメッセージを表示する', () => {
exec(['--slug', 'invalid/slug']);
expect(Log.error).toHaveBeenCalledWith(
expect.stringContaining(
Expand Down
18 changes: 9 additions & 9 deletions packages/zenn-cli/src/server/__tests__/commands/new-book.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as helper from '../../lib/helper';
import * as Log from '../../lib/log';
import { newBookHelpText } from '../../lib/messages';

describe('cli exec new:book', () => {
describe('new:book コマンドのテスト', () => {
const expectedBooksDirpath = path.join(process.cwd(), 'books');
const anyConfigYamlPathRegex = new RegExp(
`${expectedBooksDirpath}/[a-zA-Z0-9-_]+/config.yaml`
Expand All @@ -20,7 +20,7 @@ describe('cli exec new:book', () => {
console.log = jest.fn();
});

test('should call generateFileIfNotExist for config.yaml with proper arguments', () => {
test('config.yaml のデフォルト値で generateFileIfNotExist を実行する', () => {
exec([]);
expect(helper.generateFileIfNotExist).toHaveBeenCalledWith(
expect.stringMatching(anyConfigYamlPathRegex),
Expand All @@ -40,7 +40,7 @@ describe('cli exec new:book', () => {
);
});

test('should call generateFileIfNotExist for chapter files with proper arguments', () => {
test('チャプターの初期値で generateFileIfNotExist を2回実行する', () => {
const expectedChapterBody = [`---`, `title: ""`, `---`].join('\n');
exec([]);
expect(helper.generateFileIfNotExist).toHaveBeenNthCalledWith(
Expand All @@ -55,7 +55,7 @@ describe('cli exec new:book', () => {
);
});

test('should call generateFileIfNotExist with the path including slug', () => {
test('指定した slug を含むパスで generateFileIfNotExist を実装する', () => {
const slug = 'example-book';
exec(['--slug', slug]);

Expand All @@ -75,38 +75,38 @@ describe('cli exec new:book', () => {
);
});

test('should call generateFileIfNotExist for config.yaml with specified title', () => {
test('指定したタイトル文字列と config.yaml のパスで generateFileIfNotExist を実行する', () => {
exec(['--title', 'A"B/C']);
expect(helper.generateFileIfNotExist).toHaveBeenCalledWith(
expect.stringMatching(anyConfigYamlPathRegex),
expect.stringContaining(`title: "A\\"B/C"`)
);
});

test('should call generateFileIfNotExist for config.yaml with specified published value true', () => {
test('`published: true` と config.yaml のパスで generateFileIfNotExist を実行する', () => {
exec(['--published', 'true']);
expect(helper.generateFileIfNotExist).toHaveBeenCalledWith(
expect.stringMatching(anyConfigYamlPathRegex),
expect.stringContaining(`published: true`)
);
});

test('should call generateFileIfNotExist for config.yaml with specified published value false', () => {
test('`published: false` と config.yaml のパスで generateFileIfNotExist を実行する', () => {
exec(['--published', 'false']);
expect(helper.generateFileIfNotExist).toHaveBeenCalledWith(
expect.stringMatching(anyConfigYamlPathRegex),
expect.stringContaining(`published: false`)
);
});

test('should log help text with --help', () => {
test('--help オプションを渡すとヘルプメッセージを表示する', () => {
exec(['--help']);
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining(newBookHelpText)
);
});

test('should log error with invalid slug', () => {
test('無効な slug が渡されたらエラーメッセージを表示する', () => {
exec(['--slug', 'invalid/slug']);
expect(Log.error).toHaveBeenCalledWith(
expect.stringContaining(
Expand Down
18 changes: 9 additions & 9 deletions packages/zenn-cli/src/server/__tests__/commands/preview.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ import { exec } from '../../commands/preview';
import { previewHelpText } from '../../lib/messages';
import * as server from '../../lib/server';

describe('cli exec preview', () => {
describe('preview コマンドのテスト', () => {
beforeEach(() => {
console.log = jest.fn();
jest.spyOn(server, 'startServer').mockImplementation();
jest.spyOn(server, 'startLocalChangesWatcher').mockImplementation();
});

test('should log help message with --help args', async () => {
test('--help オプションを渡すとヘルプメッセージを表示する', async () => {
await exec(['--help']);
expect(console.log).toHaveBeenCalledWith(previewHelpText);
});

test('should listen with port 8000', async () => {
test('8000 ポートでサーバーを起動する', async () => {
await exec([]);
expect(server.startServer).toHaveBeenCalledWith({
port: 8000,
Expand All @@ -23,7 +23,7 @@ describe('cli exec preview', () => {
});
});

test('should listen with spcified port', async () => {
test('--port オプションで特定のポートを指定してサーバーを起動できる', async () => {
await exec(['--port', '8001']);
expect(server.startServer).toHaveBeenCalledWith({
port: 8001,
Expand All @@ -32,7 +32,7 @@ describe('cli exec preview', () => {
});
});

test('should not open browser by default', async () => {
test('デフォルトではサーバー起動時にブラウザを開かない', async () => {
await exec([]);
expect(server.startServer).toHaveBeenCalledWith({
port: expect.anything(),
Expand All @@ -41,7 +41,7 @@ describe('cli exec preview', () => {
});
});

test('should open browser if specified', async () => {
test('--open オプションを渡すとブラウザを開く', async () => {
await exec(['--open']);
expect(server.startServer).toHaveBeenCalledWith({
port: expect.anything(),
Expand All @@ -50,7 +50,7 @@ describe('cli exec preview', () => {
});
});

test('should listen with passed hostname', async () => {
test('--host オプションで hostname を指定してサーバーを起動できる', async () => {
await exec(['--host', '0.0.0.0']);
expect(server.startServer).toHaveBeenCalledWith({
hostname: '0.0.0.0',
Expand All @@ -60,15 +60,15 @@ describe('cli exec preview', () => {
});
});

test('should call startLocalChangesWatcher by default', async () => {
test('デフォルトでは startLocalChangesWatcher を実行する', async () => {
await exec([]);
expect(server.startLocalChangesWatcher).toHaveBeenCalledWith(
undefined,
`${process.cwd()}/{articles,books}/**/*`
);
});

test('should not call startLocalChangesWatcher if --no-watch specified', async () => {
test('--no-watch オプションを渡した場合は startLocalChangesWatcher を実行しない', async () => {
await exec(['--no-watch']);
expect(server.startLocalChangesWatcher).toHaveBeenCalledTimes(0);
});
Expand Down
Loading

0 comments on commit 5e8fb3b

Please sign in to comment.