From a84a615d3919f00d7677322293a17d3b5b4a4277 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Mon, 30 Sep 2019 15:28:49 +0200 Subject: [PATCH] tests: Use inline snapshots --- package-lock.json | 15 - package.json | 3 +- .../angle-brackets/__snapshots__/test.js.snap | 726 ------------------ transforms/angle-brackets/test.js | 439 +++++++++-- 4 files changed, 395 insertions(+), 788 deletions(-) delete mode 100644 transforms/angle-brackets/__snapshots__/test.js.snap diff --git a/package-lock.json b/package-lock.json index b34009c05..367e4fb60 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5038,12 +5038,6 @@ "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-1.0.1.tgz", "integrity": "sha512-j5EctnkH7amfV/q5Hgmoal1g2QHFJRraOtmx0JpIqkxhBhI/lJSl1nMpQ45hVarwNETOoWEimndZ4QK0RHxuxQ==" }, - "min-indent": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/min-indent/-/min-indent-1.0.0.tgz", - "integrity": "sha1-z8RcN+nsDY8KDsPdTvf3w6vjklY=", - "dev": true - }, "minimatch": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", @@ -6406,15 +6400,6 @@ "resolved": "https://registry.npmjs.org/strip-final-newline/-/strip-final-newline-2.0.0.tgz", "integrity": "sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==" }, - "strip-indent": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/strip-indent/-/strip-indent-3.0.0.tgz", - "integrity": "sha512-laJTa3Jb+VQpaC6DseHhF7dXVqHTfJPCRDaEbid/drOhgitgYku/letMUqOXFoWV0zIIUbjpdH2t+tYj4bQMRQ==", - "dev": true, - "requires": { - "min-indent": "^1.0.0" - } - }, "strip-json-comments": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.0.1.tgz", diff --git a/package.json b/package.json index 0cbbf1d14..54f627b15 100644 --- a/package.json +++ b/package.json @@ -40,8 +40,7 @@ "eslint": "^6.5.0", "eslint-config-prettier": "^6.3.0", "eslint-plugin-prettier": "^3.1.1", - "jest": "^24.9.0", - "strip-indent": "^3.0.0" + "jest": "^24.9.0" }, "engines": { "node": "^8 || >=10" diff --git a/transforms/angle-brackets/__snapshots__/test.js.snap b/transforms/angle-brackets/__snapshots__/test.js.snap deleted file mode 100644 index 714ce6f57..000000000 --- a/transforms/angle-brackets/__snapshots__/test.js.snap +++ /dev/null @@ -1,726 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`action-params 1`] = ` -"{{#bs-button onClick=(action \\"submit\\")}} - Button -{{/bs-button}} -~~~~~~~~ - - Button -" -`; - -exports[`actions 1`] = ` -"{{#bs-button-group - value=buttonGroupValue - type=\\"checkbox\\" - onChange=(action (mut buttonGroupValue)) as |bg| -}} - {{#bg.button value=1}}1{{/bg.button}} - {{#bg.button value=2}}2{{/bg.button}} - {{#bg.button value=3}}3{{/bg.button}} -{{/bs-button-group}} -~~~~~~~~ - - - 1 - - - 2 - - - 3 - -" -`; - -exports[`boolean-values 1`] = ` -"{{my-component prop1=true prop2=false}} -~~~~~~~~ -" -`; - -exports[`curly 1`] = ` -"
{{foo}}
-
{{{bar}}}
-~~~~~~~~ -
- {{foo}} -
-
- {{{bar}}} -
" -`; - -exports[`custom-options 1`] = ` -"{{some-component foo=true}} -{{some-helper1 foo=true}} -{{some-helper2 foo=true}} -{{link-to \\"Title\\" \\"some.route\\"}} -{{textarea value=this.model.body}} -{{input type=\\"checkbox\\" name=\\"email-opt-in\\" checked=this.model.emailPreference}} -~~~~~~~~ - -{{some-helper1 foo=true}} -{{some-helper2 foo=true}} -{{link-to \\"Title\\" \\"some.route\\"}} -{{textarea value=this.model.body}} -{{input type=\\"checkbox\\" name=\\"email-opt-in\\" checked=this.model.emailPreference}}" -`; - -exports[`data-attributes 1`] = ` -"{{x-foo data-foo=true}} -{{x-foo data-test-selector=true}} -{{x-foo data-test-selector=post.id}} -{{x-foo label=\\"hi\\" data-test-selector=true}} -{{x-foo data-test-foo }} - -{{#x-foo data-foo=true}} - block -{{/x-foo}} - -{{#x-foo data-test-selector=true}} - block -{{/x-foo}} - -{{#x-foo data-test-selector=post.id}} - block -{{/x-foo}} - -{{#common/accordion-component data-test-accordion as |accordion|}} - block -{{/common/accordion-component}} - -{{x-foo - data-foo - name=\\"Sophie\\" -}} -~~~~~~~~ - - - - - - - block - - - block - - - block - - - block - -" -`; - -exports[`deeply-nested-sub 1`] = ` -"{{#some-component class=(concat foo (some-helper ted (some-dude bar (a b c)))) }} - help -{{/some-component}} -{{some-component class=(concat foo (some-helper ted (some-dude bar (a b c)))) }} -{{deep-component class=(concat foo (nice-helper ted (some-crazy bar (a d (d e f)))))}} -{{some-component - class=(concat foo (some-helper bar)) -}} -{{some-component - class=(concat foo (some-helper bar quuz)) -}} -{{some-component - person=(hash name=\\"Sophie\\" age=1) - message=(t \\"welcome\\" count=1) -}} -{{some-component - people=(array - (hash - name=\\"Alex\\" - age=5 - nested=(hash oldest=true amount=(format-currency 350 sign=\\"£\\")) - disabled=(eq foo \\"bar\\") - ) - (hash name=\\"Ben\\" age=4) - (hash name=\\"Sophie\\" age=1) - ) -}} -~~~~~~~~ - - help - - - - - - -" -`; - -exports[`each-in 1`] = ` -"{{#each-in this.people as |name person|}} - Hello, {{name}}! You are {{person.age}} years old. -{{else}} - Sorry, nobody is here. -{{/each-in}} -~~~~~~~~ -{{#each-in this.people as |name person|}} - Hello,{{name}}! You are{{person.age}}years old. -{{else}} - Sorry, nobody is here. -{{/each-in}}" -`; - -exports[`entities 1`] = ` -"< > × -{{#foo data-a=\\""Foo & Bar"\\"}} Some text >{{/foo}} -~~~~~~~~ -< > × - -  Some text > -" -`; - -exports[`html-tags 1`] = ` -" - - - - - -
- -
-
-~~~~~~~~ - - - -
-
-
" -`; - -exports[`if 1`] = ` -"{{#if (eq a b)}} - {{my-component1 prop1=\\"hello\\"}} -{{else}} - {{my-component2 prop2=\\"world\\"}} -{{/if}} -~~~~~~~~ -{{#if (eq a b)}} - -{{else}} - -{{/if}}" -`; - -exports[`input-helper 1`] = ` -"{{input type=\\"checkbox\\" name=\\"email-opt-in\\" checked=this.model.emailPreference}} -~~~~~~~~ -" -`; - -exports[`let 1`] = ` -"{{#let (capitalize this.person.firstName) (capitalize this.person.lastName) - as |firstName lastName| -}} - Welcome back {{concat firstName ' ' lastName}} - - Account Details: - First Name: {{firstName}} - Last Name: {{lastName}} -{{/let}} -~~~~~~~~ -{{#let - (capitalize this.person.firstName) - (capitalize this.person.lastName) as |firstName lastName| -}} - Welcome back - {{concat firstName \\" \\" lastName}} - Account Details: - First Name: - {{firstName}} - Last Name: - {{lastName}} -{{/let}}" -`; - -exports[`link-to 1`] = ` -"{{#link-to \\"about\\"}}About Us{{/link-to}} -{{#link-to this.dynamicRoute}}About Us{{/link-to}} -~~~~~~~~ - - About Us - - - About Us -" -`; - -exports[`link-to-inline 1`] = ` -"{{link-to 'Title' 'some.route'}} -{{link-to - 'Segments' - 'apps.segments' - class='tabs__discrete-tab' - activeClass='o__selected' - current-when='apps.segments' - data-test-segment-link='segments' -}} -{{link-to - 'Segments' - this.dynamicPath - class='tabs__discrete-tab' - activeClass='o__selected' - current-when='apps.segments' - data-test-segment-link='segments' -}} -{{link-to - segment.name - 'apps.app.companies.segments.segment' - segment - class=\\"t__em-link\\" -}} -~~~~~~~~ - - Title - - - Segments - - - Segments - - - {{segment.name}} -" -`; - -exports[`link-to-model 1`] = ` -"{{#link-to \\"post\\" post}}Read {{post.title}}...{{/link-to}} -{{#link-to \\"post\\" \\"string-id\\"}}Read {{post.title}}...{{/link-to}} -{{#link-to \\"post\\" 557}}Read {{post.title}}...{{/link-to}} -~~~~~~~~ - - Read - {{post.title}} - ... - - - Read - {{post.title}} - ... - - - Read - {{post.title}} - ... -" -`; - -exports[`link-to-model-array 1`] = ` -"{{#link-to \\"post.comment\\" post comment}} - Comment by {{comment.author.name}} on {{comment.date}} -{{/link-to}} -{{#link-to this.dynamicPath post comment}} - Comment by {{comment.author.name}} on {{comment.date}} -{{/link-to}} -~~~~~~~~ - - Comment by - {{comment.author.name}} - on - {{comment.date}} - - - Comment by - {{comment.author.name}} - on - {{comment.date}} -" -`; - -exports[`link-to-query-param 1`] = ` -"{{#link-to \\"posts\\" (query-params direction=\\"desc\\" showArchived=false)}} - Recent Posts -{{/link-to}} -{{#link-to data-test-foo \\"posts\\"}} - Recent Posts -{{/link-to}} -{{#link-to this.dynamicPath (query-params direction=\\"desc\\" showArchived=false)}} - Recent Posts -{{/link-to}} -{{#link-to data-test-foo this.dynamicPath (query-params direction=\\"desc\\" showArchived=false)}} - Recent Posts -{{/link-to}} -{{#link-to (query-params direction=\\"desc\\" showArchived=false)}} - Recent Posts -{{/link-to}} -{{link-to - 'Users' - 'apps.app.users.segments.segment' - 'all-users' - (query-params searchTerm=searchTerm) -}} -~~~~~~~~ - - Recent Posts - - - Recent Posts - - - Recent Posts - - - Recent Posts - - - Recent Posts - - - Users -" -`; - -exports[`nested 1`] = ` -"{{ui/site-header user=this.user class=(if this.user.isAdmin \\"admin\\")}} -{{ui/button text=\\"Click me\\"}} -{{#some-path/another-path/super-select selected=this.user.country as |s|}} - {{#each this.availableCountries as |country|}} - {{#s.option value=country}}{{country.name}}{{/s.option}} - {{/each}} -{{/some-path/another-path/super-select}} -{{x-foo/x-bar}} -~~~~~~~~ - - - - {{#each this.availableCountries as |country|}} - - {{country.name}} - - {{/each}} - -" -`; - -exports[`null-subexp 1`] = ` -"{{some-component selected=(is-equal this.bar null)}} -~~~~~~~~ -" -`; - -exports[`positional-params 1`] = ` -"{{some-component \\"foo\\"}} -{{#some-component \\"foo\\"}} - hi -{{/some-component}} -{{#some-component foo}} - hi -{{/some-component}} -{{some-component 123}} -{{some-component (some-helper 987)}} -~~~~~~~~ -{{some-component \\"foo\\"}} -{{#some-component \\"foo\\"}} - hi -{{/some-component}} -{{#some-component foo}} - hi -{{/some-component}} -{{some-component 123}} -{{some-component (some-helper 987)}}" -`; - -exports[`sample 1`] = ` -"{{site-header user=this.user class=(if this.user.isAdmin \\"admin\\")}} -{{site-header user=null address=undefined}} - -{{#super-select selected=this.user.country as |s|}} - {{#each this.availableCountries as |country|}} - {{#s.option value=country}}{{country.name}}{{/s.option}} - {{/each}} -{{/super-select}} - -{{foo/bar tagName=''}} -{{foo tagName='div' a=\\"\\" b=''}} -~~~~~~~~ - - - - {{#each this.availableCountries as |country|}} - - {{country.name}} - - {{/each}} - - -" -`; - -exports[`sample2 1`] = ` -"{{#my-card as |card|}} - {{card.title title=\\"My Card Title\\"}} - {{#card.content}} -

hello

- {{/card.content}} - {{card.foo-bar}} - {{card.foo}} -{{/my-card}} -~~~~~~~~ - - - -

- hello -

-
- - {{card.foo}} -
" -`; - -exports[`skip-default-helpers (no-config) 1`] = ` -"
- {{liquid-outlet}} -
- - -{{#liquid-if showOne class=\\"nested-explode-transition-scenario\\"}} -
- {{#liquid-if showA use=\\"toLeft\\"}} -
One: A
- {{else}} -
One: B
- {{/liquid-if}} -
-{{else}} -
- Two -
-{{/liquid-if}} -{{moment '12-25-1995' 'MM-DD-YYYY'}} -{{moment-from '1995-12-25' '2995-12-25' hideAffix=true}} -{{some-component foo=true}} -{{some-helper1 foo=true}} -{{some-helper2 foo=true}} -~~~~~~~~ -
- {{liquid-outlet}} -
- - -{{#liquid-if showOne class=\\"nested-explode-transition-scenario\\"}} -
- {{#liquid-if showA use=\\"toLeft\\"}} -
- One: A -
- {{else}} -
- One: B -
- {{/liquid-if}} -
-{{else}} -
- Two -
-{{/liquid-if}} -{{moment \\"12-25-1995\\" \\"MM-DD-YYYY\\"}} -{{moment-from \\"1995-12-25\\" \\"2995-12-25\\" hideAffix=true}} - - -" -`; - -exports[`skip-default-helpers 1`] = ` -"
- {{liquid-outlet}} -
- - -{{#liquid-if showOne class=\\"nested-explode-transition-scenario\\"}} -
- {{#liquid-if showA use=\\"toLeft\\"}} -
One: A
- {{else}} -
One: B
- {{/liquid-if}} -
-{{else}} -
- Two -
-{{/liquid-if}} -{{moment '12-25-1995' 'MM-DD-YYYY'}} -{{moment-from '1995-12-25' '2995-12-25' hideAffix=true}} -{{some-component foo=true}} -{{some-helper1 foo=true}} -{{some-helper2 foo=true}} -~~~~~~~~ -
- {{liquid-outlet}} -
- - -{{#liquid-if showOne class=\\"nested-explode-transition-scenario\\"}} -
- {{#liquid-if showA use=\\"toLeft\\"}} -
- One: A -
- {{else}} -
- One: B -
- {{/liquid-if}} -
-{{else}} -
- Two -
-{{/liquid-if}} -{{moment \\"12-25-1995\\" \\"MM-DD-YYYY\\"}} -{{moment-from \\"1995-12-25\\" \\"2995-12-25\\" hideAffix=true}} - -{{some-helper1 foo=true}} -{{some-helper2 foo=true}}" -`; - -exports[`t-helper 1`] = ` -"{{t \\"some.string\\" param=\\"string\\" another=1}} -~~~~~~~~ -{{t \\"some.string\\" param=\\"string\\" another=1}}" -`; - -exports[`tag-name 1`] = ` -"{{foo/bar name=\\"\\"}} -~~~~~~~~ -" -`; - -exports[`textarea 1`] = ` -"{{textarea value=this.model.body}} -~~~~~~~~ - + +
+
+
" + `); }); test('if', () => { @@ -186,7 +282,13 @@ test('if', () => { {{/if}} `; - expect(runTest('if.hbs', input)).toMatchSnapshot(); + expect(runTest('if.hbs', input)).toMatchInlineSnapshot(` + "{{#if (eq a b)}} + + {{else}} + + {{/if}}" + `); }); test('input-helper', () => { @@ -194,7 +296,13 @@ test('input-helper', () => { {{input type="checkbox" name="email-opt-in" checked=this.model.emailPreference}} `; - expect(runTest('input-helper.hbs', input)).toMatchSnapshot(); + expect(runTest('input-helper.hbs', input)).toMatchInlineSnapshot(` + "" + `); }); test('let', () => { @@ -210,7 +318,20 @@ test('let', () => { {{/let}} `; - expect(runTest('let.hbs', input)).toMatchSnapshot(); + expect(runTest('let.hbs', input)).toMatchInlineSnapshot(` + "{{#let + (capitalize this.person.firstName) + (capitalize this.person.lastName) as |firstName lastName| + }} + Welcome back + {{concat firstName \\" \\" lastName}} + Account Details: + First Name: + {{firstName}} + Last Name: + {{lastName}} + {{/let}}" + `); }); test('link-to', () => { @@ -219,7 +340,14 @@ test('link-to', () => { {{#link-to this.dynamicRoute}}About Us{{/link-to}} `; - expect(runTest('link-to.hbs', input)).toMatchSnapshot(); + expect(runTest('link-to.hbs', input)).toMatchInlineSnapshot(` + " + About Us + + + About Us + " + `); }); test('link-to-inline', () => { @@ -249,7 +377,36 @@ test('link-to-inline', () => { }} `; - expect(runTest('link-to-inline.hbs', input)).toMatchSnapshot(); + expect(runTest('link-to-inline.hbs', input)).toMatchInlineSnapshot(` + " + Title + + + Segments + + + Segments + + + {{segment.name}} + " + `); }); test('link-to-model', () => { @@ -259,7 +416,23 @@ test('link-to-model', () => { {{#link-to "post" 557}}Read {{post.title}}...{{/link-to}} `; - expect(runTest('link-to-model.hbs', input)).toMatchSnapshot(); + expect(runTest('link-to-model.hbs', input)).toMatchInlineSnapshot(` + " + Read + {{post.title}} + ... + + + Read + {{post.title}} + ... + + + Read + {{post.title}} + ... + " + `); }); test('link-to-model-array', () => { @@ -272,7 +445,20 @@ test('link-to-model-array', () => { {{/link-to}} `; - expect(runTest('link-to-model-array.hbs', input)).toMatchSnapshot(); + expect(runTest('link-to-model-array.hbs', input)).toMatchInlineSnapshot(` + " + Comment by + {{comment.author.name}} + on + {{comment.date}} + + + Comment by + {{comment.author.name}} + on + {{comment.date}} + " + `); }); test('link-to-query-param', () => { @@ -300,7 +486,37 @@ test('link-to-query-param', () => { }} `; - expect(runTest('link-to-query-param.hbs', input)).toMatchSnapshot(); + expect(runTest('link-to-query-param.hbs', input)).toMatchInlineSnapshot(` + " + Recent Posts + + + Recent Posts + + + Recent Posts + + + Recent Posts + + + Recent Posts + + + Users + " + `); }); test('nested', () => { @@ -315,7 +531,18 @@ test('nested', () => { {{x-foo/x-bar}} `; - expect(runTest('nested.hbs', input)).toMatchSnapshot(); + expect(runTest('nested.hbs', input)).toMatchInlineSnapshot(` + " + + + {{#each this.availableCountries as |country|}} + + {{country.name}} + + {{/each}} + + " + `); }); test('null-subexp', () => { @@ -323,7 +550,9 @@ test('null-subexp', () => { {{some-component selected=(is-equal this.bar null)}} `; - expect(runTest('null-subexp.hbs', input)).toMatchSnapshot(); + expect(runTest('null-subexp.hbs', input)).toMatchInlineSnapshot( + `""` + ); }); test('positional-params', () => { @@ -339,7 +568,17 @@ test('positional-params', () => { {{some-component (some-helper 987)}} `; - expect(runTest('positional-params.hbs', input)).toMatchSnapshot(); + expect(runTest('positional-params.hbs', input)).toMatchInlineSnapshot(` + "{{some-component \\"foo\\"}} + {{#some-component \\"foo\\"}} + hi + {{/some-component}} + {{#some-component foo}} + hi + {{/some-component}} + {{some-component 123}} + {{some-component (some-helper 987)}}" + `); }); test('sample', () => { @@ -357,7 +596,19 @@ test('sample', () => { {{foo tagName='div' a="" b=''}} `; - expect(runTest('sample.hbs', input)).toMatchSnapshot(); + expect(runTest('sample.hbs', input)).toMatchInlineSnapshot(` + " + + + {{#each this.availableCountries as |country|}} + + {{country.name}} + + {{/each}} + + + " + `); }); test('sample2', () => { @@ -372,7 +623,18 @@ test('sample2', () => { {{/my-card}} `; - expect(runTest('sample2.hbs', input)).toMatchSnapshot(); + expect(runTest('sample2.hbs', input)).toMatchInlineSnapshot(` + " + + +

+ hello +

+
+ + {{card.foo}} +
" + `); }); test('t-helper', () => { @@ -380,7 +642,9 @@ test('t-helper', () => { {{t "some.string" param="string" another=1}} `; - expect(runTest('t-helper.hbs', input)).toMatchSnapshot(); + expect(runTest('t-helper.hbs', input)).toMatchInlineSnapshot( + `"{{t \\"some.string\\" param=\\"string\\" another=1}}"` + ); }); test('tag-name', () => { @@ -388,7 +652,7 @@ test('tag-name', () => { {{foo/bar name=""}} `; - expect(runTest('tag-name.hbs', input)).toMatchSnapshot(); + expect(runTest('tag-name.hbs', input)).toMatchInlineSnapshot(`""`); }); test('textarea', () => { @@ -396,7 +660,9 @@ test('textarea', () => { {{textarea value=this.model.body}} `; - expect(runTest('textarea.hbs', input)).toMatchSnapshot(); + expect(runTest('textarea.hbs', input)).toMatchInlineSnapshot( + `"