mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-18 04:24:30 +08:00
test: add tests for enhanced-resolve
This commit is contained in:
42
enhanced-resolve/enhanced-resolve-tests.ts
Normal file
42
enhanced-resolve/enhanced-resolve-tests.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import resolve = require('enhanced-resolve');
|
||||
import { Context } from './lib/concord';
|
||||
import { ResolveResult } from './lib/common-types'
|
||||
import Resolver = require('./lib/Resolver')
|
||||
|
||||
resolve('lib', 'string', function (err) { });
|
||||
|
||||
let context: Context = {
|
||||
referrer: 'hi'
|
||||
};
|
||||
|
||||
resolve(context, 'path', 'string', function () { });
|
||||
|
||||
let resolver: Resolver
|
||||
resolver = resolve.ResolverFactory.createResolver({
|
||||
extensions: ['.js'],
|
||||
fileSystem: {}
|
||||
});
|
||||
|
||||
const nfs = new resolve.NodeJsInputFileSystem();
|
||||
|
||||
const snfs = new resolve.SyncNodeJsInputFileSystem();
|
||||
|
||||
const cfs = new resolve.CachedInputFileSystem(nfs, 4);
|
||||
const cfs2 = new resolve.CachedInputFileSystem(snfs, 4);
|
||||
|
||||
let result: ResolveResult
|
||||
|
||||
result = resolve.sync(context, 'path', 'string');
|
||||
result = resolve.sync('path', 'string');
|
||||
|
||||
resolve.context('lib', 'string', function (err) { });
|
||||
resolve.context(context, 'path', 'string', function () { });
|
||||
|
||||
result = resolve.context.sync(context, 'path', 'string');
|
||||
result = resolve.context.sync('path', 'string');
|
||||
|
||||
resolve.create('lib', 'string', function (err) { });
|
||||
resolve.create(context, 'path', 'string', function () { });
|
||||
|
||||
result = resolve.create.sync(context, 'path', 'string');
|
||||
result = resolve.create.sync('path', 'string');
|
||||
48
enhanced-resolve/index.d.ts
vendored
48
enhanced-resolve/index.d.ts
vendored
@@ -6,7 +6,7 @@
|
||||
/// <reference types="node" />
|
||||
/// <reference types="tapable" />
|
||||
|
||||
import fs = require('fs')
|
||||
import fs = require('fs');
|
||||
import {
|
||||
ResolveResult,
|
||||
LoggingCallbackWrapper,
|
||||
@@ -14,36 +14,36 @@ import {
|
||||
CommonFileSystemMethod,
|
||||
BaseFileSystem,
|
||||
ResolverRequest
|
||||
} from './lib/common-types'
|
||||
import { Context } from './lib/concord'
|
||||
import Resolver = require('./lib/Resolver')
|
||||
} from './lib/common-types';
|
||||
import { Context } from './lib/concord';
|
||||
import Resolver = require('./lib/Resolver');
|
||||
|
||||
declare namespace Resolve {
|
||||
function sync(path: string, request: string): ResolveResult
|
||||
function sync(context: Context, path: string, request: string): ResolveResult
|
||||
function sync(path: string, request: string): ResolveResult;
|
||||
function sync(context: Context, path: string, request: string): ResolveResult;
|
||||
|
||||
function context(path: string, request: string, callback: LoggingCallbackWrapper): void
|
||||
function context(context: Context, path: string, request: string, callback: LoggingCallbackWrapper): void
|
||||
function context(path: string, request: string, callback: LoggingCallbackWrapper): void;
|
||||
function context(context: Context, path: string, request: string, callback: LoggingCallbackWrapper): void;
|
||||
|
||||
namespace context {
|
||||
function sync(path: string, request: string): ResolveResult
|
||||
function sync(context: Context, path: string, request: string): ResolveResult
|
||||
function sync(path: string, request: string): ResolveResult;
|
||||
function sync(context: Context, path: string, request: string): ResolveResult;
|
||||
}
|
||||
|
||||
function loader(path: string, request: string, callback: LoggingCallbackWrapper): void
|
||||
function loader(context: Context, path: string, request: string, callback: LoggingCallbackWrapper): void
|
||||
function loader(path: string, request: string, callback: LoggingCallbackWrapper): void;
|
||||
function loader(context: Context, path: string, request: string, callback: LoggingCallbackWrapper): void;
|
||||
|
||||
namespace context {
|
||||
function sync(path: string, request: string): ResolveResult
|
||||
function sync(context: Context, path: string, request: string): ResolveResult
|
||||
function sync(path: string, request: string): ResolveResult;
|
||||
function sync(context: Context, path: string, request: string): ResolveResult;
|
||||
}
|
||||
|
||||
function create(path: string, request: string, callback: LoggingCallbackWrapper): void
|
||||
function create(context: Context, path: string, request: string, callback: LoggingCallbackWrapper): void
|
||||
function create(path: string, request: string, callback: LoggingCallbackWrapper): void;
|
||||
function create(context: Context, path: string, request: string, callback: LoggingCallbackWrapper): void;
|
||||
|
||||
export namespace create {
|
||||
function sync(path: string, request: string): ResolveResult
|
||||
function sync(context: Context, path: string, request: string): ResolveResult
|
||||
function sync(path: string, request: string): ResolveResult;
|
||||
function sync(context: Context, path: string, request: string): ResolveResult;
|
||||
}
|
||||
|
||||
export namespace ResolverFactory {
|
||||
@@ -54,7 +54,7 @@ declare namespace Resolve {
|
||||
mainFields?: string[];
|
||||
aliasFields?: string[];
|
||||
mainFiles?: string[];
|
||||
extensions?: string[];
|
||||
extensions: string[];
|
||||
enforceExtension?: boolean;
|
||||
moduleExtensions?: string[];
|
||||
enforceModuleExtension?: boolean;
|
||||
@@ -63,7 +63,7 @@ declare namespace Resolve {
|
||||
resolveToContext?: boolean;
|
||||
unsafeCache?: boolean | {};
|
||||
cachePredicate?: (val: ResolverRequest) => boolean;
|
||||
fileSystem?: any;
|
||||
fileSystem: any;
|
||||
resolver?: Resolver;
|
||||
}
|
||||
interface AliasItem {
|
||||
@@ -81,8 +81,8 @@ declare namespace Resolve {
|
||||
|
||||
stat(path: string, callback?: (err: NodeJS.ErrnoException, stats: fs.Stats) => any): void;
|
||||
|
||||
readFile(filename: string, encoding: string, callback: (err: NodeJS.ErrnoException, data: string) => void): void
|
||||
readFile(filename: string, callback: (err: NodeJS.ErrnoException, data: string) => void): void
|
||||
readFile(filename: string, encoding: string, callback: (err: NodeJS.ErrnoException, data: string) => void): void;
|
||||
readFile(filename: string, callback: (err: NodeJS.ErrnoException, data: string) => void): void;
|
||||
|
||||
readlink(path: string, callback?: (err: NodeJS.ErrnoException, linkString: string) => any): void;
|
||||
}
|
||||
@@ -92,8 +92,8 @@ declare namespace Resolve {
|
||||
|
||||
stat: CommonFileSystemMethod;
|
||||
readdir: CommonFileSystemMethod;
|
||||
readFile(path: string, encoding?: string, callback?: (err: NodeJS.ErrnoException, result: Buffer) => void): void
|
||||
readFile(path: string, callback?: (err: NodeJS.ErrnoException, result: Buffer) => void): void
|
||||
readFile(path: string, encoding?: string, callback?: (err: NodeJS.ErrnoException, result: Buffer) => void): void;
|
||||
readFile(path: string, callback?: (err: NodeJS.ErrnoException, result: Buffer) => void): void;
|
||||
readlink: CommonFileSystemMethod;
|
||||
}
|
||||
|
||||
|
||||
4
enhanced-resolve/lib/Resolver.d.ts
vendored
4
enhanced-resolve/lib/Resolver.d.ts
vendored
@@ -1,7 +1,7 @@
|
||||
/// <reference types="tapable" />
|
||||
import Tapable = require('tapable');
|
||||
import { ResolveParseResult, ResolverRequest, LoggingCallbackWrapper, BaseFileSystem } from './common-types'
|
||||
import { Context } from './concord'
|
||||
import { ResolveParseResult, ResolverRequest, LoggingCallbackWrapper, BaseFileSystem } from './common-types';
|
||||
import { Context } from './concord';
|
||||
declare class Resolver extends Tapable {
|
||||
fileSystem: BaseFileSystem;
|
||||
|
||||
|
||||
2
enhanced-resolve/lib/Storage.d.ts
vendored
2
enhanced-resolve/lib/Storage.d.ts
vendored
@@ -1,5 +1,5 @@
|
||||
/// <reference types="node" />
|
||||
import { CommonFileSystemMethod } from './common-types'
|
||||
import { CommonFileSystemMethod } from './common-types';
|
||||
|
||||
declare class Storage {
|
||||
duration: number;
|
||||
|
||||
2
enhanced-resolve/lib/UnsafeCachePlugin.d.ts
vendored
2
enhanced-resolve/lib/UnsafeCachePlugin.d.ts
vendored
@@ -1,5 +1,5 @@
|
||||
import Resolver = require('./Resolver');
|
||||
import { ResolverRequest } from './common-types'
|
||||
import { ResolverRequest } from './common-types';
|
||||
declare class UnsafeCachePlugin {
|
||||
source: string;
|
||||
filterPredicate: (str: ResolverRequest) => boolean;
|
||||
|
||||
33
enhanced-resolve/lib/common-types.d.ts
vendored
33
enhanced-resolve/lib/common-types.d.ts
vendored
@@ -1,12 +1,11 @@
|
||||
import { Context } from './concord'
|
||||
/**
|
||||
* Created by cloud on 16-11-4.
|
||||
*/
|
||||
import { Context } from './concord';
|
||||
|
||||
export interface ResolveError extends Error {
|
||||
details: string;
|
||||
missing: string[];
|
||||
recursion: boolean;
|
||||
}
|
||||
|
||||
export interface ResolveParseResult {
|
||||
request: string;
|
||||
query: string;
|
||||
@@ -14,10 +13,12 @@ export interface ResolveParseResult {
|
||||
directory: boolean;
|
||||
file: boolean;
|
||||
}
|
||||
|
||||
export interface ResolveResult {
|
||||
path: boolean | string;
|
||||
query: string;
|
||||
}
|
||||
|
||||
export interface ResolverRequest {
|
||||
request: string;
|
||||
relativePath?: string;
|
||||
@@ -30,6 +31,7 @@ export interface ResolverRequest {
|
||||
directory?: boolean;
|
||||
module?: boolean;
|
||||
}
|
||||
|
||||
export interface LoggingCallbackTools {
|
||||
log?(msg: string): void;
|
||||
stack?: string[];
|
||||
@@ -37,26 +39,25 @@ export interface LoggingCallbackTools {
|
||||
push: (item: string) => void;
|
||||
};
|
||||
}
|
||||
|
||||
export interface LoggingCallbackWrapper extends LoggingCallbackTools {
|
||||
(...args: any[]): any;
|
||||
(err?: Error | null, ...args: any[]): any;
|
||||
}
|
||||
|
||||
export interface ErrorCallback {
|
||||
(err: Error | null, ...args: any[]): any
|
||||
(err: Error | null, ...args: any[]): any;
|
||||
}
|
||||
|
||||
export interface CommonFileSystemMethod {
|
||||
(name: string, callback: (err: Error | null, ...args: any[]) => void): void
|
||||
(name: string, callback: (err: Error | null, ...args: any[]) => void): void;
|
||||
}
|
||||
|
||||
export interface BaseFileSystem {
|
||||
stat: CommonFileSystemMethod
|
||||
readdir?: CommonFileSystemMethod
|
||||
readFile?(path: string, encoding: string, callback: any): void
|
||||
readFile?(path: string, callback: any): void
|
||||
readJson?: CommonFileSystemMethod
|
||||
readlink?: CommonFileSystemMethod
|
||||
isSync: () => boolean
|
||||
stat: CommonFileSystemMethod;
|
||||
readdir?: CommonFileSystemMethod;
|
||||
readFile?(path: string, encoding: string, callback: ErrorCallback): void;
|
||||
readFile?(path: string, callback: ErrorCallback): void;
|
||||
readJson?: CommonFileSystemMethod;
|
||||
readlink?: CommonFileSystemMethod;
|
||||
isSync: () => boolean;
|
||||
}
|
||||
|
||||
|
||||
|
||||
3
enhanced-resolve/lib/concord.d.ts
vendored
3
enhanced-resolve/lib/concord.d.ts
vendored
@@ -2,11 +2,13 @@ export interface Type {
|
||||
type: string | null | undefined;
|
||||
features: string[];
|
||||
}
|
||||
|
||||
export interface Context {
|
||||
supportedResourceTypes?: string[];
|
||||
environments?: string[];
|
||||
referrer: string;
|
||||
}
|
||||
|
||||
declare function parseType(type: string): Type;
|
||||
declare function isTypeMatched(baseType: string | Type, testedType: string | Type): boolean;
|
||||
declare function isResourceTypeSupported(context: Context, type: string): boolean | undefined;
|
||||
@@ -19,6 +21,7 @@ declare function getMain(context: Context, configuration: any): undefined;
|
||||
declare function getExtensions(context: Context, configuration: any): undefined;
|
||||
declare function matchModule(context: Context, configuration: any, request: string): any;
|
||||
declare function matchType(context: Context, configuration: any, relativePath: string): undefined;
|
||||
|
||||
export {
|
||||
parseType,
|
||||
isTypeMatched,
|
||||
|
||||
137
enhanced-resolve/lib/lib-tests.ts
Normal file
137
enhanced-resolve/lib/lib-tests.ts
Normal file
@@ -0,0 +1,137 @@
|
||||
import AliasFieldPlugin = require('./AliasFieldPlugin');
|
||||
|
||||
import AliasPlugin = require('./AliasPlugin');
|
||||
|
||||
import AppendPlugin = require('./AppendPlugin');
|
||||
|
||||
import CloneBasenamePlugin = require('./CloneBasenamePlugin');
|
||||
|
||||
import ConcordExtensionsPlugin = require('./ConcordExtensionsPlugin');
|
||||
|
||||
import ConcordMainPlugin = require('./ConcordMainPlugin');
|
||||
|
||||
import ConcordModulesPlugin = require('./ConcordModulesPlugin');
|
||||
|
||||
import DescriptionFilePlugin = require('./DescriptionFilePlugin');
|
||||
|
||||
import DescriptionFileUtils = require('./DescriptionFileUtils');
|
||||
|
||||
import DirectoryExistsPlugin = require('./DirectoryExistsPlugin');
|
||||
|
||||
import FileExistsPlugin = require('./FileExistsPlugin');
|
||||
|
||||
import FileKindPlugin = require('./FileKindPlugin');
|
||||
|
||||
import getPaths, { basename } from './getPaths';
|
||||
|
||||
import { globToRegExp } from './globToRegExp';
|
||||
|
||||
import JoinRequestPlugin = require('./JoinRequestPlugin');
|
||||
|
||||
import LogInfoPlugin = require('./LogInfoPlugin');
|
||||
|
||||
import MainFieldPlugin = require('./MainFieldPlugin');
|
||||
|
||||
import ModuleAppendPlugin = require('./ModuleAppendPlugin');
|
||||
|
||||
import ModuleKindPlugin = require('./ModuleKindPlugin');
|
||||
|
||||
import ModulesInHierachicDirectoriesPlugin = require('./ModulesInHierachicDirectoriesPlugin');
|
||||
|
||||
import ModulesInRootPlugin = require('./ModulesInRootPlugin');
|
||||
|
||||
import NextPlugin = require('./NextPlugin');
|
||||
|
||||
import ParsePlugin = require('./ParsePlugin');
|
||||
|
||||
import Resolver = require('./Resolver');
|
||||
|
||||
import ResultPlugin = require('./ResultPlugin');
|
||||
|
||||
import Storage from './Storage'
|
||||
|
||||
import SymlinkPlugin = require('./SymlinkPlugin');
|
||||
|
||||
import TryNextPlugin = require('./TryNextPlugin');
|
||||
|
||||
import UnsafeCachePlugin = require('./UnsafeCachePlugin');
|
||||
|
||||
import UseFilePlugin = require('./UseFilePlugin');
|
||||
|
||||
import resolve = require('../');
|
||||
|
||||
import { BaseFileSystem } from './common-types'
|
||||
|
||||
const aplugin = new AliasFieldPlugin('a', 'b', 'c');
|
||||
|
||||
const aplugin2 = new AliasPlugin('a', {
|
||||
onlyModule: false,
|
||||
name: 'a',
|
||||
alias: 'b'
|
||||
}, 'string')
|
||||
|
||||
const aplugin3 = new AppendPlugin('a', 'b', 'c');
|
||||
|
||||
const cplugin = new CloneBasenamePlugin('a', 'c');
|
||||
|
||||
const cplugin2 = new ConcordExtensionsPlugin('a', {}, 'b');
|
||||
|
||||
const cplugin3 = new ConcordMainPlugin('string', {}, 'string');
|
||||
|
||||
const cplugin4 = new ConcordModulesPlugin('string', {}, 'string');
|
||||
|
||||
const dplugin = new DescriptionFilePlugin('string', 'string', 'string');
|
||||
|
||||
DescriptionFileUtils.cdUp('./lib');
|
||||
DescriptionFileUtils.getField({}, 'hi');
|
||||
DescriptionFileUtils.loadDescriptionFile(resolve.ResolverFactory.createResolver({
|
||||
extensions: [''],
|
||||
fileSystem: {}
|
||||
}), './lib', ['file'], function () { });
|
||||
|
||||
const dplugin1 = new DirectoryExistsPlugin('string', 'string');
|
||||
|
||||
const fplugin = new FileExistsPlugin('string', 's');
|
||||
|
||||
const fplugin2 = new FileKindPlugin('string', 's');
|
||||
|
||||
getPaths('./lib');
|
||||
|
||||
basename('./lib');
|
||||
|
||||
globToRegExp('lib/**');
|
||||
|
||||
const jplugin = new JoinRequestPlugin('string', 's');
|
||||
|
||||
const lplugin = new LogInfoPlugin('string');
|
||||
|
||||
const mplugin = new MainFieldPlugin('string', {
|
||||
name: 'hi',
|
||||
forceRelative: false
|
||||
}, 's');
|
||||
|
||||
const mplugin2 = new ModuleAppendPlugin('string', 'ap', 's');
|
||||
|
||||
const mplugin3 = new ModuleKindPlugin('string', 's');
|
||||
|
||||
const mplugin4 = new ModulesInHierachicDirectoriesPlugin('string', ['arr'], 's');
|
||||
|
||||
const mplugin5 = new ModulesInRootPlugin('string', 'ap', 's');
|
||||
|
||||
const nplugin = new NextPlugin('string', 'ap');
|
||||
|
||||
const pplugin = new ParsePlugin('string', 'ap');
|
||||
|
||||
const resolver = new Resolver({} as BaseFileSystem);
|
||||
|
||||
const rplugin = new ResultPlugin('string');
|
||||
|
||||
const splugin = new SymlinkPlugin('string', 's');
|
||||
|
||||
const tplugin = new TryNextPlugin('string', 'ap', 's');
|
||||
|
||||
const uplugin = new UnsafeCachePlugin('string', function (e) { return false }, {}, 's');
|
||||
|
||||
const uplugin2 = new UseFilePlugin('string', 'ap', 's');
|
||||
|
||||
const s = new Storage(4);
|
||||
@@ -1,18 +1,20 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es6",
|
||||
"noImplicitAny": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"include": [
|
||||
"**/*.ts"
|
||||
]
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es6",
|
||||
"noImplicitAny": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"include": [
|
||||
"index.d.ts",
|
||||
"enhanced-resolve-tests.ts",
|
||||
"lib/*.ts"
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user