deno_std icon indicating copy to clipboard operation
deno_std copied to clipboard

tracking: format test names

Open timreichen opened this issue 1 year ago • 6 comments

Ref: https://github.com/denoland/deno_std/issues/2553#issuecomment-1784006070

This issue tracks the implementation progress of adapting the following format for test names in each sub-module:

<symbol>() <description> // E.g. ensureDir() creates the directory if it doesn't exist
  • [x] archive
  • [x] assert
  • [x] async
  • [x] bytes
  • [x] cli
  • [ ] collections
  • [x] console
  • [x] crypto
  • [ ] csv
  • [x] datetime
  • [ ] dotenv
  • [ ] encoding
  • [ ] flags
  • [ ] fmt
  • [ ] front_matter
  • [x] fs
  • [ ] html
  • [ ] http
  • [ ] io
  • [ ] json
  • [ ] jsonc
  • [ ] log
  • [ ] media_types
  • [ ] msgpack
  • [x] path
  • [ ] permissions
  • [x] regexp
  • [ ] semver
  • [ ] signal
  • [ ] streams
  • [ ] testing
  • [ ] toml
  • [ ] ulid
  • [ ] url
  • [x] uuid
  • [ ] wasi
  • [ ] yaml

timreichen avatar Oct 31 '23 20:10 timreichen

I'm working on fs - should be done tomorrow

JakeAve avatar Nov 22 '23 00:11 JakeAve

https://github.com/denoland/deno-docs/blob/2c90cc2eca70c484e5fbfc61d256bf7342a2e95e/runtime/manual/references/contributing/style_guide.md?plain=1#L310-L327

maybe the test name rules could be documented in deno manual. should I open PR/issue?

scarf005 avatar Dec 07 '23 11:12 scarf005

Ah, yes. We do need to add something in the contributing guidelines. A PR would be welcome!

iuioiua avatar Dec 07 '23 11:12 iuioiua

Is there a way to make the linter enforce this?

syhol avatar Dec 18 '23 17:12 syhol

Would it be worth using the bdd.ts describe blocks to define the subject under test?

Deno.test({
  name: "[std/datetime] isLeap",
  fn() {
    assert(isLeap(1992));
    assert(isLeap(2000));
    assert(!isLeap(2003));
    assert(!isLeap(2007));
    assert(!isLeap(new Date("1970-01-02")));
    assert(isLeap(new Date("1972-01-02")));
    assert(isLeap(new Date("2000-01-02")));
    assert(!isLeap(new Date("2100-01-02")));
  },
});

to

import { describe, it } from "../testing/bdd.ts";

describe("isLeap()", () => {
  it("identifies leap years for numbers", () => {
    assert(isLeap(1992));
    assert(isLeap(2000));
    assert(!isLeap(2003));
    assert(!isLeap(2007));
  });

  it("identifies leap years for Date instances", () => {
    assert(!isLeap(new Date("1970-01-02")));
    assert(isLeap(new Date("1972-01-02")));
    assert(isLeap(new Date("2000-01-02")));
    assert(!isLeap(new Date("2100-01-02")));
  });
});

It forces the format you're after: Subject under test and description of desired behaviour

The big downside is that you loose the test integration in vscode: image

syhol avatar Dec 18 '23 21:12 syhol

docs: unified test names

I don't think so.

Would it be worth using the bdd.ts describe blocks to define the subject under test?

The current approach of using std/assert with Deno.test() (and steps, if needed) already works fine.

iuioiua avatar Dec 18 '23 21:12 iuioiua

For anyone wanting to contribute, only std/testing remains.

iuioiua avatar Apr 10 '24 07:04 iuioiua