{"id":16704159,"url":"https://github.com/aazuspan/should-test","last_synced_at":"2025-04-10T05:05:30.642Z","repository":{"id":129061865,"uuid":"482684462","full_name":"aazuspan/should-test","owner":"aazuspan","description":"Build and run unit tests in the Earth Engine code editor","archived":false,"fork":false,"pushed_at":"2023-02-06T05:25:31.000Z","size":69,"stargazers_count":10,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T06:12:00.460Z","etag":null,"topics":["assert","assertions","code-editor","earth-engine","gee","javascript","testing","unit-testing"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aazuspan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-04-18T02:06:24.000Z","updated_at":"2023-04-18T23:32:40.000Z","dependencies_parsed_at":null,"dependency_job_id":"fe3f5a19-87bd-413f-b84f-09d49b74a256","html_url":"https://github.com/aazuspan/should-test","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aazuspan%2Fshould-test","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aazuspan%2Fshould-test/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aazuspan%2Fshould-test/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aazuspan%2Fshould-test/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aazuspan","download_url":"https://codeload.github.com/aazuspan/should-test/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248161280,"owners_count":21057554,"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":["assert","assertions","code-editor","earth-engine","gee","javascript","testing","unit-testing"],"created_at":"2024-10-12T19:11:30.483Z","updated_at":"2025-04-10T05:05:30.635Z","avatar_url":"https://github.com/aazuspan.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# should-test\n\n[![Earth Engine Javascript](https://img.shields.io/badge/Earth%20Engine%20API-Javascript-red)](https://developers.google.com/earth-engine/tutorials/tutorial_api_01)\n[![Open in Code Editor](https://img.shields.io/badge/Open%20in-Code%20Editor-9cf)](https://code.earthengine.google.com/d5309955cc7d2e7c0ab0dee9bd156d30)\n\n\n- ☑️ Write one-line unit tests in the [Google Earth Engine](https://earthengine.google.com/) code editor\n- ⏱️ Evaluate client or server-side objects asynchronously\n\n# Quickstart\n\nFirst, import the `should:test` module into your script.\n\n```javascript\nvar should = require(\"users/aazuspan/should:test\");\n```\n\nThen write your first test.\n\n```javascript\nshould.equal(ee.Number(42), 42, \"Check numbers are equal\");\n```\n\nHit `run` and the test will evaluate and let you know if it passed ✅ or failed 🛑. Write more tests and `should-test` will run them and summarize the results, printing out any errors that occur.\n\n![Demonstration of tests running in the code editor console.](assets/should_demo.gif)\n\n# Usage\n\n## Server and Client Objects\n\nTests in `should-test` work transparently with client- and server-side objects. For example, both of the following work:\n\n```javascript\nvar year = 2022;\nshould.beGreater(year, 2010, \"Check client-side year\");\n```\n\n```javascript\nvar year = ee\n  .Image(\"LANDSAT/LC09/C02/T1_L2/LC09_001006_20220404\")\n  .date()\n  .get(\"year\");\nshould.beGreater(year, 2010, \"Check server-side year\");\n```\n\nTests with Earth Engine objects run asynchronously and report their results when finished, so there's no risk of freezing the browser with `getInfo`.\n\n## Filtering Tests\n\nBy default, all the tests you've called will evaluate when you run your script. To filter tests that run, call `should.settings.skip` and/or `should.settings.run` at the top of your script. These functions match a regular expression pattern against the test descriptions and skip or run accordingly.\n\n```javascript\nshould.settings.run(\"band\");\n\nshould.contain(image.bandNames(), \"SR_B4\", \"check for band\"); // run\nshould.beLess(collection.size(), 100, \"compare size\"); // skipped\n```\n\n## Writing Complex Tests\n\nIn order to run each test, the `should` assertion needs to be called. For organization, you can combine the assertion and any setup steps needed into a function and call that function, like so:\n\n```javascript\n// Build the test\nvar myTest = function () {\n  var l9 = ee.ImageCollection(\"LANDSAT/LC09/C02/T1_L2\");\n  var geom = ee.Geometry.Point([-112.690234375, 41.13290902574011]);\n  var col = l9.filterBounds(geom);\n  var cloudless = col.filter(ee.Filter.lt(\"CLOUD_COVER\", 5));\n\n  should.beGreater(cloudless.size(), 1, \"check # of cloud-free images\");\n};\n\n// Run the test\nmyTest();\n```\n\nFor convenience, you can skip naming and calling your test function using `should.utils.call`, like so:\n\n```javascript\n// Build and run the test\nshould.utils.call(function () {\n  var l9 = ee.ImageCollection(\"LANDSAT/LC09/C02/T1_L2\");\n  var geom = ee.Geometry.Point([-112.690234375, 41.13290902574011]);\n  var col = l9.filterBounds(geom);\n  var cloudless = col.filter(ee.Filter.lt(\"CLOUD_COVER\", 5));\n\n  should.beGreater(cloudless.size(), 1, \"check # of cloud-free images\");\n});\n```\n\n## Testing Functions\n\nThere are two assertions that test whether a function throws an error: `should.throw` and `should.notThrow`. To use these, be sure to pass the callable function, not it's evaluated result. For example:\n\n```javascript\nvar myFunction = function () {\n  print(\"Hello world\");\n};\n\n// Correct!\nshould.throw(myFunction);\n\n// Incorrect! This will test the return value of the function instead of the function.\nshould.throw(myFunction());\n```\n\nIf the function you want to test requires arguments, you can pass them using an anonymous function.\n\n```javascript\nvar myFunction = function(message) { print(message) };\n\n// Wrap your function in an anonymous function to pass arguments\nshould.notThrow(function() {\n    myFunction(\"Hello world\");\n}\n```\n\n# API Reference\n\n## Assertions\n\nAssertions test a condition and fail when false. All assertions take a `description` that is used to log test results.\n\n### Comparisons\n\nTo use a comparison assertion, Earth Engine objects must implement the corresponding operator, e.g. `eq`, `neq`, `gt`, etc.\n\n- `should.beTrue(value, description)`: The `value` should be true (strict for JS objects).\n- `should.beFalse(value, description)`: The `value` should be false (strict for JS objects).\n- `should.equal(actual, expected, description)`: The `actual` should equal the expected.\n- `should.notEqual(actual, expected, description)`: The `actual` should not equal the `expected`.\n- `should.almostEqual(actual, expected, description, error)`: The `actual` should be within a relative `error` (default `1e-6`) of the `expected`.\n- `should.beGreater(value, other, description)`: The `value` should be greater than `other`.\n- `should.beGreaterOrEqual(value, other, description)`: The `value` should be greater than or equal to `other`.\n- `should.beLess(value, other, description)`: The `value` should be less than `other`.\n- `should.beLessOrEqual(value, other, description)`: The `value` should be less than or equal to `other`.\n\n### Other\n\n- `should.match(string, pattern, description)`: The regex `pattern` should match the `string`. \n- `should.notMatch(string, pattern, description)`: The regex `pattern` should not match the `string`. \n- `should.contain(list, value, description)`: The `list` should contain the `value`.\n- `should.notContain(list, value, description)` The `list` should not contain the `value`.\n\n### Functions\n\n- `should.throw(function, description)`: Calling `function` should throw an error.\n- `should.notThrow(function, description)`: Calling `function` should not throw an error.\n\n### Assets\n\n- `should.exist(assetID, description)`: The asset should exist.\n- `should.bePublic(assetID, description)`: The asset should be public. Only usable by the asset owner or writer.\n\n### Settings\n\n- `should.settings.skip(pattern)`: Tests with descriptions that match the regex `pattern` are skipped.\n- `should.settings.run(pattern)`: Only tests with descriptions that match the regex `pattern` are run.\n\n### Utilities\n\n- `should.utils.call(func)`: Call `func`. Handy for wrapping anonymous functions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faazuspan%2Fshould-test","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faazuspan%2Fshould-test","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faazuspan%2Fshould-test/lists"}