Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove more trailing whitespaces for component fixture snapshot #961

Merged
merged 1 commit into from
Jun 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .husky/.gitignore

This file was deleted.

30 changes: 30 additions & 0 deletions .husky/_/husky.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/sh
if [ -z "$husky_skip_init" ]; then
debug () {
[ "$HUSKY_DEBUG" = "1" ] && echo "husky (debug) - $1"
}

readonly hook_name="$(basename "$0")"
debug "starting $hook_name..."

if [ "$HUSKY" = "0" ]; then
debug "HUSKY env variable is set to 0, skipping hook"
exit 0
fi

if [ -f ~/.huskyrc ]; then
debug "sourcing ~/.huskyrc"
. ~/.huskyrc
fi

export readonly husky_skip_init=1
sh -e "$0" "$@"
exitCode="$?"

if [ $exitCode != 0 ]; then
echo "husky - $hook_name hook exited with code $exitCode (error)"
exit $exitCode
fi

exit 0
fi
4 changes: 3 additions & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn lint-staged
yarn lint:fix
yarn lint:prettier
git add .
Original file line number Diff line number Diff line change
@@ -1,12 +1,36 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`snapshot should work 1`] = `
<foo
__ngContext__={[Function LRootView]}
condition1={[Function Boolean]}
condition2="false"
value1={[Function String]}
value2={[Function String]}
>
<p>
Line 1
</p><div>
<div>
val1
</div>
</div>
</foo>
`;

exports[`snapshot should work 2`] = `
<div
id="root0"
>
<p>
simple-with-styles works!

Line 1
</p>
<div>
<div>
val1
</div>


</div>
</div>
`;
12 changes: 9 additions & 3 deletions e2e/snapshot-serializers/__tests__/foo.component.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<p>
simple-with-styles works!
</p>
<p>Line 1</p>
<div>
<div *ngIf="condition1">
{{ value1 }}
</div>
<span *ngIf="condition2">
{{ value2 }}
</span>
</div>
11 changes: 9 additions & 2 deletions e2e/snapshot-serializers/__tests__/foo.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component } from '@angular/core';
import { Component, Input } from '@angular/core';
import { TestBed, waitForAsync } from '@angular/core/testing';

@Component({
Expand All @@ -14,7 +14,13 @@ import { TestBed, waitForAsync } from '@angular/core/testing';
`,
],
})
class FooComponent {}
class FooComponent {
@Input() value1 = 'val1';
@Input() value2 = 'val2';

condition1 = true;
condition2 = false;
}

test(
'snapshot should work',
Expand All @@ -26,6 +32,7 @@ test(
const fixture = TestBed.createComponent(FooComponent);
fixture.detectChanges();

expect(fixture).toMatchSnapshot();
expect(fixture.debugElement.nativeElement).toMatchSnapshot();
}),
);
7 changes: 0 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,13 @@
"husky": "^6.0.0",
"jest": "^27.0.4",
"jest-snapshot-serializer-raw": "^1.2.0",
"lint-staged": "^11.0.0",
"pinst": "^2.1.6",
"prettier": "^2.3.1",
"rxjs": "^6.6.7",
"tslib": "^2.2.0",
"typescript": "~4.1.5",
"zone.js": "^0.11.4"
},
"lint-staged": {
"*.{ts,js}": [
"eslint --fix",
"git add"
]
},
"engines": {
"node": "^12.13.0 || ^14.15.0 || >=15.0.0"
}
Expand Down
4 changes: 2 additions & 2 deletions src/serializers/ng-snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const print = (
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
componentName = fixture.componentRef._elDef.element?.name;
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
nodes = (fixture.componentRef._view.nodes || [])
nodes = (fixture.componentRef._view.nodes ?? [])
// eslint-disable-next-line no-prototype-builtins
.filter((node: VEDebugNode) => node?.hasOwnProperty('renderElement'))
.map((node: VEDebugNode) => Array.from(node.renderElement.childNodes).map(print).join(''))
Expand All @@ -118,7 +118,7 @@ const print = (
'\n</' +
componentName +
'>'
);
).replace(/\n^\s*\n/gm, '\n');
};

// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
Expand Down
Loading