本文整理汇总了TypeScript中tape.Test类的典型用法代码示例。如果您正苦于以下问题:TypeScript Test类的具体用法?TypeScript Test怎么用?TypeScript Test使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Test类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: test
test("Test Get Product - NOT existing vendor and device", async (t: Test) => {
const device = await getProduct("lolo", "haha").catch((err) => t.pass());
if (device) {
return t.end("Fake device was found");
} else {
t.end();
}
});
示例2: prepare
export default function prepare (t: Test, pkg?: Object) {
dirNumber++
const dirname = dirNumber.toString()
const pkgTmpPath = path.join(tmpPath, dirname, 'project')
mkdirp.sync(pkgTmpPath)
const json = JSON.stringify(pkg || {})
fs.writeFileSync(path.join(pkgTmpPath, 'package.json'), json, 'utf-8')
process.chdir(pkgTmpPath)
t.pass(`create testing package ${dirname}`)
const modules = path.join(pkgTmpPath, 'node_modules')
let cachedStorePath: string
const project = {
requireModule (pkgName: string) {
return require(path.join(modules, pkgName))
},
has: async function (pkgName: string) {
t.ok(await exists(path.join(modules, pkgName)), `${pkgName} is in node_modules`)
},
hasNot: async function (pkgName: string) {
t.ok(!await exists(path.join(modules, pkgName)), `${pkgName} is not in node_modules`)
},
getStorePath: async function () {
if (!cachedStorePath) {
const modulesYaml = await readModules(modules)
if (!modulesYaml) {
throw new Error('Cannot find module store')
}
cachedStorePath = modulesYaml.storePath
}
return cachedStorePath
},
resolve: async function (pkgName: string, version?: string, relativePath?: string) {
const pkgFolder = version ? path.join('localhost+4873', pkgName, version) : pkgName
if (relativePath) {
return path.join(await project.getStorePath(), pkgFolder, relativePath)
}
return path.join(await project.getStorePath(), pkgFolder)
},
storeHas: async function (pkgName: string, version?: string) {
t.ok(await exists(await project.resolve(pkgName, version)), `${pkgName}@${version} is in store`)
},
storeHasNot: async function (pkgName: string, version?: string) {
try {
t.ok(!await exists(await project.resolve(pkgName, version)), `${pkgName}@${version} is not in store`)
} catch (err) {
if (err.message === 'Cannot find module store') {
t.pass(`${pkgName}@${version} is not in store`)
return
}
throw err
}
},
isExecutable: function (pathToExe: string) {
return isExecutable(t, path.join(modules, pathToExe))
},
}
return project
}
示例3: function
storeHasNot: async function (pkgName: string, version?: string) {
try {
t.ok(!await exists(await project.resolve(pkgName, version)), `${pkgName}@${version} is not in store`)
} catch (err) {
if (err.message === 'Cannot find module store') {
t.pass(`${pkgName}@${version} is not in store`)
return
}
throw err
}
},