简体   繁体   English

如何在 deno 测试中通过命令行 arguments?

[英]How to pass command line arguments in deno test?

For example:例如:

Deno.test({
  name: "Testing qr-html generation",
  fn: async () => {
    await createQRhtml();
    assertEquals(exists("out/qr.html"), true);
  }
});

createQRhtml() function takes arguments from command line. createQRhtml() function 从命令行获取 arguments。 Specifically, first argument: Deno.args[0] .具体来说,第一个参数: Deno.args[0]

How to specify here?这里如何指定?

You can pass your CLI arguments after a double dash ( -- ) like this:您可以在双破折号 ( -- ) 之后传递 CLI arguments,如下所示:

deno test args.test.ts -- hello

args.test.ts : args.test.ts

import {assert} from 'https://deno.land/std@0.109.0/testing/asserts.ts';

function isHello (str?: unknown): boolean {
  return str === 'hello';
}

Deno.test('First CLI argument is "hello"', () => {
  const [firstArg] = Deno.args;
  assert(isHello(firstArg));
});

You can learn about the test commmand and other commands in your CLI using the form:您可以使用以下形式了解 CLI 中的test命令和其他命令:

deno help COMMAND_NAME

This is included in the output of deno help test :这包含在deno help test的 output 中:

USAGE:
    deno test [OPTIONS] [files]... [-- <SCRIPT_ARG>...]

See also: https://github.com/denoland/deno/issues/8096另见: https://github.com/denoland/deno/issues/8096

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM