{"id":18045596,"url":"https://github.com/piroor/tiny-esm-test-runner","last_synced_at":"2025-04-10T01:33:11.210Z","repository":{"id":65516537,"uuid":"268691533","full_name":"piroor/tiny-esm-test-runner","owner":"piroor","description":"Small test runner for ESModules style modules on Node.js","archived":false,"fork":false,"pushed_at":"2022-03-16T06:29:22.000Z","size":75,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"trunk","last_synced_at":"2025-03-27T15:48:43.578Z","etag":null,"topics":["esmodules","hacktoberfest","javascript","test-runner"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/piroor.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-06-02T03:26:15.000Z","updated_at":"2022-12-18T12:58:26.000Z","dependencies_parsed_at":"2023-01-26T22:25:13.866Z","dependency_job_id":null,"html_url":"https://github.com/piroor/tiny-esm-test-runner","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piroor%2Ftiny-esm-test-runner","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piroor%2Ftiny-esm-test-runner/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piroor%2Ftiny-esm-test-runner/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piroor%2Ftiny-esm-test-runner/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/piroor","download_url":"https://codeload.github.com/piroor/tiny-esm-test-runner/tar.gz/refs/heads/trunk","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248140309,"owners_count":21054276,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["esmodules","hacktoberfest","javascript","test-runner"],"created_at":"2024-10-30T18:13:44.471Z","updated_at":"2025-04-10T01:33:11.185Z","avatar_url":"https://github.com/piroor.png","language":"JavaScript","readme":"# tiny-esm-test-runner\n\n![Build Status](https://github.com/piroor/tiny-esm-test-runner/actions/workflows/main.yml/badge.svg?branch=trunk)\n\nSmall test runner for ES modules style modules on Node.js.\n**This is for you ES modules addict, if you hope to write tests for ES modules as ES modules strictly.**\n\n## Benefits\n\nA testcase written for this testing framework are completely valid ES module.\nThus you don't need to put any ugly exceptions for `eslint` about your testcases, and it will allow you to keep testcases more strict easily.\n\n## How to create test cases\n\nFirst, please create test files as module files. For example:\n\n```javascript\n// Save as \"test-example.js\"\n\nimport { assert } from 'tiny-esm-test-runner';\nconst { is, isNot, ok, ng } = assert;\n\n// Function (both sync and async) exported with the name \"setUp\" is\n// automatically detected as the common setup for each test.\n// This is optional.\nexport function setUp() {\n  // common setup process\n}\n\n// Function (both sync and async) exported with the name \"tearDown\" is\n// automatically detected as the common teardown for each test.\n// This is optional.\nexport function tearDown() {\n  // common teardown process\n}\n\n// Function (both sync and async) exported with the name \"shutDown\" is\n// automatically detected as the finalization process for all tests.\n// This is optional.\nexport function shutDown() {\n  // the finalization process\n}\n\n// All functions (both sync and async) exported with a name starting\n// with the prefix \"test\" are automatically detected as tests.\nexport function testSuccess() {\n  const expected = 'AAA';\n  const actual = 'aaa'.toUpperCase();\n  is(expected, actual);\n}\n\nexport function testFail() {\n  const expected = 'AAA';\n  const actual = 'aaa'.toLowerCase();\n  is(expected, actual);\n}\n```\n\nAfter that run the `run-tiny-esm-test-runner` command with created testcase files, like:\n\n```bash\n$ run-tiny-esm-test-runner test-*.js\n```\n\nThe command returns `0` if all tests succeeded. Otherwise `1` will be returned and details are printed.\n\n## [Deno](https://deno.land/) support\n\nYou can run the test runner on [Deno](https://deno.land/), like:\n\n```bash\n$ git clone https://github.com/piroor/tiny-esm-test-runner.git\n$ deno install --allow-read --allow-write --allow-net tiny-esm-test-runner/bin/run-tiny-esm-test-runner.deno\n$ tiny-esm-test-runner test-*.js\n```\n\nPlease note that you need to import assertions from the online resource:\n\n```\nimport { is, ok, ng } from 'https://github.com/piroor/tiny-esm-test-runner/raw/master/lib/assert.js';\n```\n\n## For your modules\n\nIf you develop a npm module, you'll put the test script like:\n\n```json\n{\n  \"scripts\": {\n    ...\n    \"test\": \"run-tiny-esm-test-runner test/test-*.js\"\n  },\n  \"devDependencies\": {\n    ...\n    \"tiny-esm-test-runner\": \"^1.1.0\"\n  }\n}\n```\n\nAfter that, you just run `npm install \u0026\u0026 npm test` to do tests.\n\n## Available assertions\n\n### `is(expected, actual, message)`\n\nThis assertion accepts two or three arguments:\n\n* `expected` (required, any type): The expected value.\n* `actual` (required, any type): The actual value.\n* `message` (optional, `string`): An extra message printed when the assertion failed.\n\nThis succeeds when the actual value equals to the given expected value, based on the `===` operator.\nEven if they are not exact same, they are re-compared again as JSON strings if they are JSON-stringifiable objects (`Object`, `Array`, and so on).\n\n\n### `isNot(expected, actual, message)`\n\nThis assertion accepts two or three arguments:\n\n* `expected` (required, any type): The expected value.\n* `actual` (required, any type): The actual value.\n* `message` (optional, `string`): An extra message printed when the assertion failed.\n\nThis is opposite of `is()`, succeeds when the actual value does not equal to the given expected value, based on the `!==` operator.\nThey are also re-compared again as JSON strings if they are JSON-stringifiable objects (`Object`, `Array`, and so on).\n\n### `ok(actual, message)`\n\nThis assertion accepts one or two arguments:\n\n* `actual` (required, any type): The actual value.\n* `message` (optional, `string`): An extra message printed when the assertion failed.\n\nThis succeeds when the actual value is detected as `true` on JavaScript.\n\n### `ng(actual, message)`\n\nThis assertion accepts one or two arguments:\n\n* `actual` (required, any type): The actual value.\n* `message` (optional, `string`): An extra message printed when the assertion failed.\n\nThis is opposite of `ok()`, succeeds when the actual value is detected as `false` on JavaScript.\n\n## Data driven tests\n\nIf you set a `parameters` property to a test function, it will become a data-driven test. For example:\n\n```javascript\ntestUpperCase.parameters = [\n  ['AAA', 'aaa'],\n  ['BBB', 'bbb']\n];\nexport function testUpperCase([expected, data]) {\n  is(expected, data.toUpperCase());\n}\n```\n\nor\n\n```javascript\ntestUpperCase.parameters = {\n  a: ['AAA', 'aaa'],\n  b: ['BBB', 'bbb']\n};\nexport function testUpperCase([expected, data]) {\n  is(expected, data.toUpperCase());\n}\n```\n\nThe `parameters` property must be an `Array` or an `Object`.\nIf you specify an `Array`, the test function will be called multiple times for each element.\nIf you specify an `Object`, the test function will be called multiple times with values for each key.\n\nGiven parameters are available on `setUp()` and `tearDown()` also.\n\n## For debugging\n\nIf you set `runnable` property to test functions with any `true` compatible value, only such flagged tests are executed and other tests are skipped.\nThis will help you to run only some failed tests again and again on debugging.\nFor example:\n\n```javascript\n// This test is skipped.\nexport function testSuccess() {\n  const expected = 'AAA';\n  const actual = 'aaa'.toUpperCase();\n  is(expected, actual);\n}\n\n// This test is executed.\ntestFail.runnable = true;\nexport function testFail() {\n  const expected = 'AAA';\n  const actual = 'aaa'.toLowerCase();\n  is(expected, actual);\n}\n```\n\n# Example usecases\n\n* [self test](./tests/)\n* https://github.com/piroor/webextensions-lib-dom-updater/tree/master/test\n* https://github.com/piroor/copy-selected-tabs-to-clipboard/tree/master/test\n* https://github.com/piroor/xulmigemo/tree/master/webextensions/test\n\n# License\n\nMIT\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpiroor%2Ftiny-esm-test-runner","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpiroor%2Ftiny-esm-test-runner","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpiroor%2Ftiny-esm-test-runner/lists"}