Skip to content

Commit

Permalink
Merge branch 'rellafella:upgrade-test-system' into master
Browse files Browse the repository at this point in the history
Close GH-43.

Re-structure tests to allow configuration per-test basis.
  • Loading branch information
zackad committed Aug 14, 2024
2 parents 15d1a91 + 3354cca commit 1b69010
Show file tree
Hide file tree
Showing 102 changed files with 1,671 additions and 2,448 deletions.
8 changes: 8 additions & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"baseUrl": ".",
"module": "ES2022",
"moduleResolution": "Bundler"
},
"exclude": ["node_modules"]
}
3 changes: 1 addition & 2 deletions src/melody/melody-extension-core/visitors/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
* limitations under the License.
*/
import * as t from "@babel/types";
import _template from "@babel/template";
const template = _template.default;
import template from "@babel/template";
// use default value if var is null, undefined or an empty string
// but use var if value is 0, false, an empty array or an empty object
const defaultFilter = template("VAR != null && VAR !== '' ? VAR : DEFAULT");
Expand Down
3 changes: 1 addition & 2 deletions src/melody/melody-extension-core/visitors/for.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
*/
import { traverse } from "../../melody-traverse/index.js";
import * as t from "@babel/types";
import _template from "@babel/template";
const babelTemplate = _template.default;
import babelTemplate from "@babel/template";

// @param template
// @returns function
Expand Down
14 changes: 14 additions & 0 deletions tests/Comments/__snapshots__/htmlComments.snap.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!-- I am a comment -->
This is a paragraph

<!-- I am a second comment -->

Another paragraph

<!-- I am a third comment -->

A third paragraph

<!-- This is the story of a little lamb
that gets lost in a dark forest and
struggles to find home -->
98 changes: 0 additions & 98 deletions tests/Comments/__snapshots__/jsfmt.spec.js.snap

This file was deleted.

29 changes: 29 additions & 0 deletions tests/Comments/__snapshots__/twigComments.snap.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{# One #}

{# Two #}

{# comment #}

{# comment #}

{# comment
#}

{% if searchResultFailing %}
{# This is a Twig comment #}
<li>No results found</li>
{% endif %}

{#- comment -#}

{#-
comment
with multiple lines
-#}

{##
# Illustration Hotel Interaction
#
# This image is just of decorative nature and doesn't contain relevant information
# for visually impaired users.
#}
19 changes: 18 additions & 1 deletion tests/Comments/jsfmt.spec.js
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
run_spec(__dirname, ["twig"]);
import { run_spec } from "tests_config/run_spec";
import { describe, expect, it } from "vitest";

describe("Comments", () => {
it("should handle html comments", async () => {
const { actual, snapshotFile } = await run_spec(import.meta.url, {
source: "htmlComments.twig"
});
await expect(actual).toMatchFileSnapshot(snapshotFile);
});

it("should handle twig comments", async () => {
const { actual, snapshotFile } = await run_spec(import.meta.url, {
source: "twigComments.twig"
});
await expect(actual).toMatchFileSnapshot(snapshotFile);
});
});
1 change: 1 addition & 0 deletions tests/ConstantValue/__snapshots__/int.snap.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
123
30 changes: 0 additions & 30 deletions tests/ConstantValue/__snapshots__/jsfmt.spec.js.snap

This file was deleted.

5 changes: 5 additions & 0 deletions tests/ConstantValue/__snapshots__/special.snap.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% if isRTL %}&#8206;{% endif %}

{% if searchResultFailing %}
<li><span><!-- // --></span>No results found</li>
{% endif %}
1 change: 1 addition & 0 deletions tests/ConstantValue/__snapshots__/string.snap.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test string
File renamed without changes.
24 changes: 23 additions & 1 deletion tests/ConstantValue/jsfmt.spec.js
Original file line number Diff line number Diff line change
@@ -1 +1,23 @@
run_spec(__dirname, ["twig"]);
import { run_spec } from "tests_config/run_spec";
import { describe, expect, it } from "vitest";

describe("Constant values", () => {
it("should handle constant value int", async () => {
const { actual, snapshotFile } = await run_spec(import.meta.url, {
source: "int.twig"
});
expect(actual).toMatchFileSnapshot(snapshotFile);
});
it("should handle constant value string", async () => {
const { actual, snapshotFile } = await run_spec(import.meta.url, {
source: "string.twig"
});
expect(actual).toMatchFileSnapshot(snapshotFile);
});
it("should handle constant value special cases", async () => {
const { actual, snapshotFile } = await run_spec(import.meta.url, {
source: "special.twig"
});
expect(actual).toMatchFileSnapshot(snapshotFile);
});
});
File renamed without changes.
File renamed without changes.
15 changes: 15 additions & 0 deletions tests/ControlStructures/__snapshots__/for.snap.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<ul>
{% for item in items %}
<li class="{{ loop.last ? 'last' : '' }}">
{{ loop.index0 // 2 }} {{ item.name }} {{ loop.index }}
</li>
{% endfor %}
</ul>

<ul>
{%- for item in items -%}
<li class="{{ loop.last ? 'last' : '' }}">
{{ loop.index0 // 2 }} {{ item.name }} {{ loop.index }}
</li>
{%- endfor -%}
</ul>
18 changes: 18 additions & 0 deletions tests/ControlStructures/__snapshots__/forIfElse.snap.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<ul>
{% for a, b in c|slice(3, c.length) if b is even -%}
<li>{{ a }} - {{ b }}</li>
{%- else %}
<li>No results found</li>
{%- endfor %}
</ul>

<ul>
{% for key, value in c[:c.length - 1]
if value is defined and value is not even %}
<li>{{ key }} - {{ value }}</li>
{% else -%}
{% if regionName is empty %}
<li><span><!-- // --></span>No results found</li>
{% endif %}
{% endfor -%}
</ul>
6 changes: 6 additions & 0 deletions tests/ControlStructures/__snapshots__/forInclude.snap.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{% for foo in range(1, category) %}
<span key="{{ foo }}"
class="qtp-item__star icon-ic icon-icn_star--white {{ foo }}">
{% include './Star.twig' only %}
</span>
{% endfor %}
12 changes: 12 additions & 0 deletions tests/ControlStructures/__snapshots__/forWithBlock.snap.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<h1>
{{ title|title }}
</h1>
<ul>
{% for item in items %}
<li class="{{ loop.last ? 'last' : '' }}">
{% block title %}
{{ loop.index0 }} {{ item.name|title }} {{ loop.index }}
{% endblock %}
</li>
{% endfor %}
</ul>
31 changes: 31 additions & 0 deletions tests/ControlStructures/__snapshots__/if.snap.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<div>
{%- if foo %}
<div class="foo"></div>
{% else -%}
<div class="bar"></div>
{%- endif %}
</div>

{% if partner -%}
<img class="{{ {
(css.logo): not useWiderItems,
(css.logoWider): useWiderItems
}|classes }}"
srcABC="{{ partner.logoUrl }}"
alt="{{ partner.name }}" />
{%- elseif partnerName %}
<b class="{{ css.name }}">{{ partnerName }}</b>
{% elseif partnerImg -%}
<b class="{{ css.image }}">{{ partnerImg }}</b>
{%- endif -%}

<!-- Don't break -->
{% if isLeftToRight %}Hund{% endif %}
{% if isRTL %}{{ '&#8206;'|raw }}{% endif %}

<!-- Do break -->
{% if (unitAfter|length) > 0 and not withoutDisplayPattern %}
<span key="unit-after" class="unit unit--after">{{ unitAfter }}</span>
{% endif %}

{%- if isCTestActive('WEB-50808') %} web50808{% endif -%}
Loading

0 comments on commit 1b69010

Please sign in to comment.