Skip to content

Commit

Permalink
Add more tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Jul 25, 2023
1 parent 0867b03 commit 305f86f
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 9 deletions.
14 changes: 14 additions & 0 deletions crates/cli/tests/generate_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,20 @@ fn renders_with_custom_vars_via_args() {
assert_snapshot!(fs::read_to_string(sandbox.path().join("./test/control.txt")).unwrap());
}

#[test]
fn handles_raw_files() {
let sandbox = generate_sandbox();

let assert = sandbox.run_moon(|cmd| {
cmd.arg("generate").arg("standard").arg("./test");
});

assert.success();

assert_snapshot!(fs::read_to_string(sandbox.path().join("./test/file.txt")).unwrap());
assert_snapshot!(fs::read_to_string(sandbox.path().join("./test/other.txt")).unwrap());
}

#[test]
fn interpolates_destination_path() {
let sandbox = generate_sandbox();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
source: crates/cli/tests/generate_test.rs
assertion_line: 56
expression: get_path_safe_output(&assert)
expression: assert.output_standardized()
---

Template title (dry run)
Expand All @@ -11,6 +10,7 @@ Some description of the template and its files.
created --> ./test/file.ts
created --> ./test/file.txt
created --> ./test/folder/nested-file.ts
created --> ./test/other.raw.txt



Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
source: crates/cli/tests/generate_test.rs
assertion_line: 37
expression: get_path_safe_output(&assert)
expression: assert.output_standardized()
---

Template title
Expand All @@ -11,6 +10,7 @@ Some description of the template and its files.
created --> ./test/file.ts
created --> ./test/file.txt
created --> ./test/folder/nested-file.ts
created --> ./test/other.raw.txt



Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
source: crates/cli/tests/generate_test.rs
expression: "fs::read_to_string(sandbox.path().join(\"./test/other.txt\")).unwrap()"
---
{% set my_var = 2 %}
{{ my_var }}

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: crates/cli/tests/generate_test.rs
expression: "fs::read_to_string(sandbox.path().join(\"./test/file.txt\")).unwrap()"
---
2

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
source: crates/cli/tests/generate_test.rs
assertion_line: 81
expression: get_path_safe_output(&assert)
expression: assert.output_standardized()
---

Template title
Expand All @@ -11,6 +10,7 @@ Some description of the template and its files.
replaced -> ./test/file.ts
replaced -> ./test/file.txt
replaced -> ./test/folder/nested-file.ts
replaced -> ./test/other.raw.txt



4 changes: 2 additions & 2 deletions crates/core/archive/tests/tree_differ_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ fn loads_all_files() {
let sandbox = create_sandbox("generator");
let differ = TreeDiffer::load(sandbox.path(), &string_vec!["templates"]).unwrap();

assert_eq!(differ.files.len(), 21);
assert_eq!(differ.files.len(), 22);
}

#[test]
fn loads_using_globs() {
let sandbox = create_sandbox("generator");
let differ = TreeDiffer::load(sandbox.path(), &string_vec!["templates/**/*"]).unwrap();

assert_eq!(differ.files.len(), 21);
assert_eq!(differ.files.len(), 22);
}

#[test]
Expand Down
3 changes: 3 additions & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#### 🚀 Updates

- Identifiers (project names, file groups, etc) can now be prefixed with underscores (`_`).
- **Codegen**
- Templates can be used as-is without rendering with [Tera](https://tera.netlify.app) by appending
a `.raw` extension.

#### 🐞 Fixes

Expand Down
3 changes: 2 additions & 1 deletion tests/fixtures/generator/templates/standard/file.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
content
{% set my_var = 2 %}
{{ my_var }}
2 changes: 2 additions & 0 deletions tests/fixtures/generator/templates/standard/other.raw.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{% set my_var = 2 %}
{{ my_var }}

0 comments on commit 305f86f

Please sign in to comment.