From 195d3c29b31dd8f28053d9cb4f7700f03e599bbf Mon Sep 17 00:00:00 2001 From: Vincent LE GOFF Date: Tue, 12 Mar 2019 09:48:01 +0100 Subject: [PATCH 1/5] Add test style guide --- website/style_guide.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/website/style_guide.md b/website/style_guide.md index bb0a643ef4591..efcc68a7e8ffa 100644 --- a/website/style_guide.md +++ b/website/style_guide.md @@ -262,3 +262,35 @@ the first column of the comment. For example: Code examples should not contain additional comments. It is already inside a comment. If it needs further comments is not a good example. + +## Each module should come with tests + +Each module should come with its test as a sibling with the name `modulename_test.ts`. For example the module `foo.ts` should come with its sibling `foo_test.ts`. + +## Unit Tests should be explicit + +For a better understanding of the tests, function should be correctly named as its prompted throught the test command. Like: + +``` +test myTestFunction ... ok +``` +Example of test: + +```ts +import { assertStrContains } from "./asserts.ts"; +import { test } from "./mod.ts"; + +test(function testingAssertStringContains() { + assertStrContains("Denosaurus", "saur"); + assertStrContains("Denosaurus", "Deno"); + assertStrContains("Denosaurus", "rus"); + let didThrow; + try { + assertStrContains("Denosaurus", "Raptor"); + didThrow = false; + } catch (e) { + didThrow = true; + } + assertEquals(didThrow, true); +}); +``` From 146d1d9e2dab4553c61bf39dbe45d9881a8ff184 Mon Sep 17 00:00:00 2001 From: Vincent LE GOFF Date: Tue, 12 Mar 2019 10:00:00 +0100 Subject: [PATCH 2/5] format --- website/style_guide.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/website/style_guide.md b/website/style_guide.md index efcc68a7e8ffa..5caea6aea524e 100644 --- a/website/style_guide.md +++ b/website/style_guide.md @@ -265,15 +265,19 @@ comment. If it needs further comments is not a good example. ## Each module should come with tests -Each module should come with its test as a sibling with the name `modulename_test.ts`. For example the module `foo.ts` should come with its sibling `foo_test.ts`. +Each module should come with its test as a sibling with the name +`modulename_test.ts`. For example the module `foo.ts` should come with its +sibling `foo_test.ts`. ## Unit Tests should be explicit -For a better understanding of the tests, function should be correctly named as its prompted throught the test command. Like: +For a better understanding of the tests, function should be correctly named as +its prompted throught the test command. Like: ``` test myTestFunction ... ok ``` + Example of test: ```ts From dd3ae2be9d299143a9b7dc1683db64963f96a1d1 Mon Sep 17 00:00:00 2001 From: Vincent LE GOFF Date: Tue, 12 Mar 2019 11:26:03 +0100 Subject: [PATCH 3/5] review fix --- website/style_guide.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/website/style_guide.md b/website/style_guide.md index 5caea6aea524e..f1b75f672c9a6 100644 --- a/website/style_guide.md +++ b/website/style_guide.md @@ -272,7 +272,7 @@ sibling `foo_test.ts`. ## Unit Tests should be explicit For a better understanding of the tests, function should be correctly named as -its prompted throught the test command. Like: +its prompted throughout the test command. Like: ``` test myTestFunction ... ok @@ -281,8 +281,8 @@ test myTestFunction ... ok Example of test: ```ts -import { assertStrContains } from "./asserts.ts"; -import { test } from "./mod.ts"; +import { assertStrContains } from "https://deno.land/std@v0.3.1/testing/asserts.ts"; +import { test } from "https://deno.land/std@v0.3.1/testing/mod.ts"; test(function testingAssertStringContains() { assertStrContains("Denosaurus", "saur"); From 57c0224213f736ad846521cb12e564234b4626ff Mon Sep 17 00:00:00 2001 From: LE GOFF Vincent Date: Wed, 13 Mar 2019 08:21:32 +0100 Subject: [PATCH 4/5] mismatching function names --- website/style_guide.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/style_guide.md b/website/style_guide.md index f1b75f672c9a6..a8afc7c15a4c4 100644 --- a/website/style_guide.md +++ b/website/style_guide.md @@ -284,7 +284,7 @@ Example of test: import { assertStrContains } from "https://deno.land/std@v0.3.1/testing/asserts.ts"; import { test } from "https://deno.land/std@v0.3.1/testing/mod.ts"; -test(function testingAssertStringContains() { +test(function myTestFunction() { assertStrContains("Denosaurus", "saur"); assertStrContains("Denosaurus", "Deno"); assertStrContains("Denosaurus", "rus"); From 4408422e4c34b1a0aac3a8beae837343f1504777 Mon Sep 17 00:00:00 2001 From: LE GOFF Vincent Date: Wed, 13 Mar 2019 19:40:50 +0100 Subject: [PATCH 5/5] review --- website/style_guide.md | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/website/style_guide.md b/website/style_guide.md index a8afc7c15a4c4..849b0b86a1bc4 100644 --- a/website/style_guide.md +++ b/website/style_guide.md @@ -281,20 +281,11 @@ test myTestFunction ... ok Example of test: ```ts -import { assertStrContains } from "https://deno.land/std@v0.3.1/testing/asserts.ts"; +import { assertEquals } from "https://deno.land/std@v0.3.1/testing/asserts.ts"; import { test } from "https://deno.land/std@v0.3.1/testing/mod.ts"; +import { foo } from "./mod.ts"; test(function myTestFunction() { - assertStrContains("Denosaurus", "saur"); - assertStrContains("Denosaurus", "Deno"); - assertStrContains("Denosaurus", "rus"); - let didThrow; - try { - assertStrContains("Denosaurus", "Raptor"); - didThrow = false; - } catch (e) { - didThrow = true; - } - assertEquals(didThrow, true); + assertEquals(foo(), { bar: "bar" }); }); ```