@nahisaho/katashiro-core 1.3.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/testing/index.d.ts +7 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +7 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/test-utils.d.ts +92 -0
- package/dist/testing/test-utils.d.ts.map +1 -0
- package/dist/testing/test-utils.js +121 -0
- package/dist/testing/test-utils.js.map +1 -0
- package/package.json +8 -8
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 nahisaho
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
CHANGED
|
@@ -14,4 +14,6 @@ export type { LogLevel, LogEntry, Logger as LoggerInterface } from './logger.js'
|
|
|
14
14
|
export { Logger, LoggerClass, createLogger } from './logger.js';
|
|
15
15
|
export { KatashiroError, parseErrorCode, ErrorCodes, withRetry, retry, withRetryPromise, calculateBackoffDelay, DEFAULT_RETRY_CONFIG, } from './errors/index.js';
|
|
16
16
|
export type { ErrorModule, ErrorCategory, StructuredErrorCode, KatashiroErrorOptions, SerializedError, RetryConfig, ErrorCodeKey, ErrorCodeValue, RetryResult, RetryCallbacks, } from './errors/index.js';
|
|
17
|
+
export { getTestEnvironment, shouldSkipExternalServices, shouldSkipOllama, shouldSkipNetwork, shouldSkipTest, getOllamaHost, getOllamaModel, getEmbeddingModel, getTestTimeout, delay, withRetry as withTestRetry, withTimeout, } from './testing/index.js';
|
|
18
|
+
export type { TestEnvironment, ConditionalTestOptions } from './testing/index.js';
|
|
17
19
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,YAAY,EAAE,MAAM,EAAE,EAAE,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAGnD,YAAY,EAEV,EAAE,EACF,SAAS,EACT,GAAG,EAEH,WAAW,EACX,YAAY,EACZ,aAAa,EAEb,MAAM,EACN,cAAc,EAEd,OAAO,EACP,WAAW,EAEX,cAAc,IAAI,oBAAoB,EACtC,SAAS,IAAI,eAAe,GAC7B,MAAM,YAAY,CAAC;AAGpB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Ac,EACd,cAAc,EAEd,UAAU,EAEV,SAAS,EACT,KAAK,EACL,gBAAgB,EAChB,qBAAqB,EAErB,oBAAoB,GACrB,MAAM,mBAAmB,CAAC;AAE3B,YAAY,EAEV,WAAW,EACX,aAAa,EACb,mBAAmB,EACnB,qBAAqB,EACrB,eAAe,EACf,WAAW,EACX,YAAY,EACZ,cAAc,EACd,WAAW,EACX,cAAc,GACf,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EACL,kBAAkB,EAClB,0BAA0B,EAC1B,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,EACd,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,cAAc,EACd,KAAK,EACL,SAAS,IAAI,aAAa,EAC1B,WAAW,GACZ,MAAM,oBAAoB,CAAC;AAE5B,YAAY,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -20,4 +20,6 @@ ErrorCodes,
|
|
|
20
20
|
withRetry, retry, withRetryPromise, calculateBackoffDelay,
|
|
21
21
|
// デフォルト設定
|
|
22
22
|
DEFAULT_RETRY_CONFIG, } from './errors/index.js';
|
|
23
|
+
// テストユーティリティ
|
|
24
|
+
export { getTestEnvironment, shouldSkipExternalServices, shouldSkipOllama, shouldSkipNetwork, shouldSkipTest, getOllamaHost, getOllamaModel, getEmbeddingModel, getTestTimeout, delay, withRetry as withTestRetry, withTimeout, } from './testing/index.js';
|
|
23
25
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAuBnD,UAAU;AACV,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAItE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhE,4BAA4B;AAC5B,OAAO;AACL,SAAS;AACT,cAAc,EACd,cAAc;AACd,WAAW;AACX,UAAU;AACV,cAAc;AACd,SAAS,EACT,KAAK,EACL,gBAAgB,EAChB,qBAAqB;AACrB,UAAU;AACV,oBAAoB,GACrB,MAAM,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAuBnD,UAAU;AACV,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAItE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhE,4BAA4B;AAC5B,OAAO;AACL,SAAS;AACT,cAAc,EACd,cAAc;AACd,WAAW;AACX,UAAU;AACV,cAAc;AACd,SAAS,EACT,KAAK,EACL,gBAAgB,EAChB,qBAAqB;AACrB,UAAU;AACV,oBAAoB,GACrB,MAAM,mBAAmB,CAAC;AAgB3B,aAAa;AACb,OAAO,EACL,kBAAkB,EAClB,0BAA0B,EAC1B,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,EACd,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,cAAc,EACd,KAAK,EACL,SAAS,IAAI,aAAa,EAC1B,WAAW,GACZ,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Testing utilities
|
|
3
|
+
*
|
|
4
|
+
* @module @nahisaho/katashiro-core/testing
|
|
5
|
+
*/
|
|
6
|
+
export { getTestEnvironment, shouldSkipExternalServices, shouldSkipOllama, shouldSkipNetwork, shouldSkipTest, getOllamaHost, getOllamaModel, getEmbeddingModel, getTestTimeout, delay, withRetry, withTimeout, type TestEnvironment, type ConditionalTestOptions, } from './test-utils.js';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,kBAAkB,EAClB,0BAA0B,EAC1B,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,EACd,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,cAAc,EACd,KAAK,EACL,SAAS,EACT,WAAW,EACX,KAAK,eAAe,EACpB,KAAK,sBAAsB,GAC5B,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Testing utilities
|
|
3
|
+
*
|
|
4
|
+
* @module @nahisaho/katashiro-core/testing
|
|
5
|
+
*/
|
|
6
|
+
export { getTestEnvironment, shouldSkipExternalServices, shouldSkipOllama, shouldSkipNetwork, shouldSkipTest, getOllamaHost, getOllamaModel, getEmbeddingModel, getTestTimeout, delay, withRetry, withTimeout, } from './test-utils.js';
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,kBAAkB,EAClB,0BAA0B,EAC1B,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,EACd,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,cAAc,EACd,KAAK,EACL,SAAS,EACT,WAAW,GAGZ,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test Utilities - テスト共通ユーティリティ
|
|
3
|
+
*
|
|
4
|
+
* @requirement REQ-TEST-001
|
|
5
|
+
* @description テスト環境の設定とモック管理
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* テスト環境設定
|
|
9
|
+
*/
|
|
10
|
+
export interface TestEnvironment {
|
|
11
|
+
/** CI環境かどうか */
|
|
12
|
+
isCI: boolean;
|
|
13
|
+
/** モックモードかどうか */
|
|
14
|
+
isMockMode: boolean;
|
|
15
|
+
/** Ollama接続可能かどうか */
|
|
16
|
+
isOllamaAvailable: boolean;
|
|
17
|
+
/** テストタイムアウト設定 */
|
|
18
|
+
timeouts: {
|
|
19
|
+
unit: number;
|
|
20
|
+
integration: number;
|
|
21
|
+
e2e: number;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* テスト環境を取得
|
|
26
|
+
*/
|
|
27
|
+
export declare function getTestEnvironment(): TestEnvironment;
|
|
28
|
+
/**
|
|
29
|
+
* 外部サービス依存テストをスキップするかどうか
|
|
30
|
+
*/
|
|
31
|
+
export declare function shouldSkipExternalServices(): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Ollama依存テストをスキップするかどうか
|
|
34
|
+
*/
|
|
35
|
+
export declare function shouldSkipOllama(): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* ネットワーク依存テストをスキップするかどうか
|
|
38
|
+
*/
|
|
39
|
+
export declare function shouldSkipNetwork(): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* 条件付きテストの設定オブジェクト
|
|
42
|
+
*/
|
|
43
|
+
export interface ConditionalTestOptions {
|
|
44
|
+
skipIf: () => boolean;
|
|
45
|
+
skipReason?: string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* スキップ条件を評価(テストランナー非依存)
|
|
49
|
+
* テストファイル内で使用:
|
|
50
|
+
* @example
|
|
51
|
+
* const skip = shouldSkipTest({ skipIf: shouldSkipOllama, skipReason: 'Ollama not available' });
|
|
52
|
+
* const testFn = skip.shouldSkip ? it.skip : it;
|
|
53
|
+
* testFn(skip.testName('should connect to Ollama'), async () => { ... });
|
|
54
|
+
*/
|
|
55
|
+
export declare function shouldSkipTest(options: ConditionalTestOptions): {
|
|
56
|
+
shouldSkip: boolean;
|
|
57
|
+
reason: string;
|
|
58
|
+
testName: (name: string) => string;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Ollamaホスト取得(環境変数対応)
|
|
62
|
+
*/
|
|
63
|
+
export declare function getOllamaHost(): string;
|
|
64
|
+
/**
|
|
65
|
+
* Ollamaモデル取得(環境変数対応)
|
|
66
|
+
*/
|
|
67
|
+
export declare function getOllamaModel(): string;
|
|
68
|
+
/**
|
|
69
|
+
* Embeddingモデル取得(環境変数対応)
|
|
70
|
+
*/
|
|
71
|
+
export declare function getEmbeddingModel(): string;
|
|
72
|
+
/**
|
|
73
|
+
* テストタイムアウト取得
|
|
74
|
+
*/
|
|
75
|
+
export declare function getTestTimeout(type?: 'unit' | 'integration' | 'e2e'): number;
|
|
76
|
+
/**
|
|
77
|
+
* 遅延実行(テスト用)
|
|
78
|
+
*/
|
|
79
|
+
export declare function delay(ms: number): Promise<void>;
|
|
80
|
+
/**
|
|
81
|
+
* リトライ付き非同期実行
|
|
82
|
+
*/
|
|
83
|
+
export declare function withRetry<T>(fn: () => Promise<T>, options?: {
|
|
84
|
+
maxRetries?: number;
|
|
85
|
+
delay?: number;
|
|
86
|
+
onRetry?: (error: Error, attempt: number) => void;
|
|
87
|
+
}): Promise<T>;
|
|
88
|
+
/**
|
|
89
|
+
* タイムアウト付き実行
|
|
90
|
+
*/
|
|
91
|
+
export declare function withTimeout<T>(fn: () => Promise<T>, timeoutMs: number, errorMessage?: string): Promise<T>;
|
|
92
|
+
//# sourceMappingURL=test-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-utils.d.ts","sourceRoot":"","sources":["../../src/testing/test-utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,eAAe;IACf,IAAI,EAAE,OAAO,CAAC;IACd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EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CAC9C,GACL,OAAO,CAAC,CAAC,CAAC,CAiBZ;AAED;;GAEG;AACH,wBAAsB,WAAW,CAAC,CAAC,EACjC,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,SAAS,EAAE,MAAM,EACjB,YAAY,SAAwB,GACnC,OAAO,CAAC,CAAC,CAAC,CAOZ"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test Utilities - テスト共通ユーティリティ
|
|
3
|
+
*
|
|
4
|
+
* @requirement REQ-TEST-001
|
|
5
|
+
* @description テスト環境の設定とモック管理
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* テスト環境を取得
|
|
9
|
+
*/
|
|
10
|
+
export function getTestEnvironment() {
|
|
11
|
+
const isCI = process.env.CI === 'true' || process.env.GITHUB_ACTIONS === 'true';
|
|
12
|
+
const isMockMode = process.env.MOCK_MODE === 'true' || process.env.USE_MOCK === 'true';
|
|
13
|
+
return {
|
|
14
|
+
isCI,
|
|
15
|
+
isMockMode: isMockMode || isCI, // CI環境では自動的にモックモード
|
|
16
|
+
isOllamaAvailable: !isCI && !isMockMode, // CI/モックモードでない場合のみ
|
|
17
|
+
timeouts: {
|
|
18
|
+
unit: 5000,
|
|
19
|
+
integration: 30000,
|
|
20
|
+
e2e: 60000,
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* 外部サービス依存テストをスキップするかどうか
|
|
26
|
+
*/
|
|
27
|
+
export function shouldSkipExternalServices() {
|
|
28
|
+
const env = getTestEnvironment();
|
|
29
|
+
return env.isCI || env.isMockMode;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Ollama依存テストをスキップするかどうか
|
|
33
|
+
*/
|
|
34
|
+
export function shouldSkipOllama() {
|
|
35
|
+
return shouldSkipExternalServices();
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* ネットワーク依存テストをスキップするかどうか
|
|
39
|
+
*/
|
|
40
|
+
export function shouldSkipNetwork() {
|
|
41
|
+
const env = getTestEnvironment();
|
|
42
|
+
return env.isCI || process.env.SKIP_NETWORK === 'true';
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* スキップ条件を評価(テストランナー非依存)
|
|
46
|
+
* テストファイル内で使用:
|
|
47
|
+
* @example
|
|
48
|
+
* const skip = shouldSkipTest({ skipIf: shouldSkipOllama, skipReason: 'Ollama not available' });
|
|
49
|
+
* const testFn = skip.shouldSkip ? it.skip : it;
|
|
50
|
+
* testFn(skip.testName('should connect to Ollama'), async () => { ... });
|
|
51
|
+
*/
|
|
52
|
+
export function shouldSkipTest(options) {
|
|
53
|
+
const shouldSkip = options.skipIf();
|
|
54
|
+
const reason = options.skipReason ?? 'skipped';
|
|
55
|
+
return {
|
|
56
|
+
shouldSkip,
|
|
57
|
+
reason,
|
|
58
|
+
testName: (name) => (shouldSkip ? `${name} (${reason})` : name),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Ollamaホスト取得(環境変数対応)
|
|
63
|
+
*/
|
|
64
|
+
export function getOllamaHost() {
|
|
65
|
+
return process.env.OLLAMA_HOST ?? 'http://192.168.224.1:11434';
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Ollamaモデル取得(環境変数対応)
|
|
69
|
+
*/
|
|
70
|
+
export function getOllamaModel() {
|
|
71
|
+
return process.env.OLLAMA_MODEL ?? 'qwen2.5:7b';
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Embeddingモデル取得(環境変数対応)
|
|
75
|
+
*/
|
|
76
|
+
export function getEmbeddingModel() {
|
|
77
|
+
return process.env.EMBEDDING_MODEL ?? 'bge-m3';
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* テストタイムアウト取得
|
|
81
|
+
*/
|
|
82
|
+
export function getTestTimeout(type = 'unit') {
|
|
83
|
+
const env = getTestEnvironment();
|
|
84
|
+
return env.timeouts[type];
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* 遅延実行(テスト用)
|
|
88
|
+
*/
|
|
89
|
+
export function delay(ms) {
|
|
90
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* リトライ付き非同期実行
|
|
94
|
+
*/
|
|
95
|
+
export async function withRetry(fn, options = {}) {
|
|
96
|
+
const { maxRetries = 3, delay: retryDelay = 1000, onRetry } = options;
|
|
97
|
+
let lastError;
|
|
98
|
+
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
99
|
+
try {
|
|
100
|
+
return await fn();
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
lastError = error instanceof Error ? error : new Error(String(error));
|
|
104
|
+
if (attempt < maxRetries) {
|
|
105
|
+
onRetry?.(lastError, attempt);
|
|
106
|
+
await delay(retryDelay * attempt);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
throw lastError;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* タイムアウト付き実行
|
|
114
|
+
*/
|
|
115
|
+
export async function withTimeout(fn, timeoutMs, errorMessage = 'Operation timed out') {
|
|
116
|
+
return Promise.race([
|
|
117
|
+
fn(),
|
|
118
|
+
new Promise((_, reject) => setTimeout(() => reject(new Error(errorMessage)), timeoutMs)),
|
|
119
|
+
]);
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=test-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-utils.js","sourceRoot":"","sources":["../../src/testing/test-utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAoBH;;GAEG;AACH,MAA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MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;YACtE,IAAI,OAAO,GAAG,UAAU,EAAE,CAAC;gBACzB,OAAO,EAAE,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;gBAC9B,MAAM,KAAK,CAAC,UAAU,GAAG,OAAO,CAAC,CAAC;YACpC,CAAC;QACH,CAAC;IACH,CAAC;IAED,MAAM,SAAS,CAAC;AAClB,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,EAAoB,EACpB,SAAiB,EACjB,YAAY,GAAG,qBAAqB;IAEpC,OAAO,OAAO,CAAC,IAAI,CAAC;QAClB,EAAE,EAAE;QACJ,IAAI,OAAO,CAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAC/B,UAAU,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC,EAAE,SAAS,CAAC,CAC7D;KACF,CAAC,CAAC;AACL,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nahisaho/katashiro-core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "KATASHIRO Core - 共通型・ユーティリティ",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -15,12 +15,6 @@
|
|
|
15
15
|
"files": [
|
|
16
16
|
"dist"
|
|
17
17
|
],
|
|
18
|
-
"scripts": {
|
|
19
|
-
"build": "tsc",
|
|
20
|
-
"clean": "rm -rf dist",
|
|
21
|
-
"test": "vitest run",
|
|
22
|
-
"test:watch": "vitest"
|
|
23
|
-
},
|
|
24
18
|
"keywords": [
|
|
25
19
|
"katashiro",
|
|
26
20
|
"core"
|
|
@@ -38,5 +32,11 @@
|
|
|
38
32
|
"homepage": "https://github.com/nahisaho/katashiro#readme",
|
|
39
33
|
"bugs": {
|
|
40
34
|
"url": "https://github.com/nahisaho/katashiro/issues"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsc",
|
|
38
|
+
"clean": "rm -rf dist",
|
|
39
|
+
"test": "vitest run",
|
|
40
|
+
"test:watch": "vitest"
|
|
41
41
|
}
|
|
42
|
-
}
|
|
42
|
+
}
|