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

Storybook addon Jest angular suport #3532

Merged
merged 16 commits into from
May 7, 2018
Merged

Storybook addon Jest angular suport #3532

merged 16 commits into from
May 7, 2018

Conversation

klimentru1986
Copy link
Contributor

What I did

  • remove Karma and add Jest in Angular example app
  • add addon Jest configuration and story in Angular example app
  • update addon Jest documentation for Angular
  • update addons support table Jest+Angular

@Hypnosphi
Copy link
Member

cc @igor-dv

@@ -28,6 +32,7 @@
"@angular/cli": "1.7.4",
"@angular/compiler-cli": "^5.2.10",
"@storybook/addon-actions": "4.0.0-alpha.4",
"@storybook/addon-jest": "^3.4.3",
Copy link
Member

@igor-dv igor-dv May 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please update to the 4.0.0-alpha (and bootstrap again, because lock file is wrong now)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed)

@codecov
Copy link

codecov bot commented May 5, 2018

Codecov Report

Merging #3532 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@          Coverage Diff           @@
##           master   #3532   +/-   ##
======================================
  Coverage    92.5%   92.5%           
======================================
  Files           6       6           
  Lines          40      40           
  Branches        2       2           
======================================
  Hits           37      37           
  Misses          2       2           
  Partials        1       1

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e9d423d...507ec7b. Read the comment docs.


Assuming that you have created a test files `my.component.spec.ts` and `my-other.comonent.spec.ts`

Config Jest with [jest-preset-angular](https://www.npmjs.com/package/jest-preset-angular)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*Configure

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


Config Jest with [jest-preset-angular](https://www.npmjs.com/package/jest-preset-angular)

In project `typings.d.ts` add
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*In project's typings.d.ts add

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


storiesOf('MyComponent', module)
.addDecorator(wTests('my.component', 'my-other.component'))
.add('This story shows test results from MyComponent.test.js and MyOtherComponent.test.js', () => (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my.component.spec.ts, my-other.comonent.spec.ts ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need only name.
Extension added in withTests.ts

In addons\jest\src\index.js it look like

new RegExp(`${name}${jestTestFilesExt}`).test(t.name)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, you wrote above

Assuming that you have created a test files my.component.spec.ts and my-other.comonent.spec.ts

So I think it's better to have the same naming

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -0,0 +1 @@
{"numFailedTestSuites":0,"numFailedTests":0,"numPassedTestSuites":1,"numPassedTests":3,"numPendingTestSuites":0,"numPendingTests":0,"numRuntimeErrorTestSuites":0,"numTotalTestSuites":1,"numTotalTests":3,"snapshot":{"added":0,"didUpdate":false,"failure":false,"filesAdded":0,"filesRemoved":0,"filesUnmatched":0,"filesUpdated":0,"matched":0,"total":0,"unchecked":0,"uncheckedKeys":[],"unmatched":0,"updated":0},"startTime":1525561826280,"success":true,"testResults":[{"assertionResults":[{"ancestorTitles":["AppComponent"],"failureMessages":[],"fullName":"AppComponent should create the app","location":null,"status":"passed","title":"should create the app"},{"ancestorTitles":["AppComponent"],"failureMessages":[],"fullName":"AppComponent should have as title 'app'","location":null,"status":"passed","title":"should have as title 'app'"},{"ancestorTitles":["AppComponent"],"failureMessages":[],"fullName":"AppComponent should render title in a h1 tag","location":null,"status":"passed","title":"should render title in a h1 tag"}],"endTime":1525561829266,"message":"","name":"/home/kliment/Projects/storybook/examples/angular-cli/src/app/app.component.spec.ts","startTime":1525561827019,"status":"passed","summary":""}],"wasInterrupted":false}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be gitignored?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

circleci tests are crash when ignore .jest-test-results.json
because the file was not found

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it should be generated on a build command, shouldn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it`s work in angular-cli application and generate output for angular-cli application.

yarn test --core run before build and crash

Summary of all failing tests
 FAIL  examples/angular-cli/angularshots.test.js
  ● Test suite failed to run

    Cannot find module '../.jest-test-results.json' from 'withTests.ts'

How can i fix it? Maybe write separate task for angular in scripts/test.js? How can i run it before yarn test --core?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe leave .jest-test-results.json in this example project?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed. .jest-test-results.json removed and test crashed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's commit then. Just checked we have a similar file for the React example, so it's ok. Let's just call it "addon-jest.testresults.json" for the convention.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@igor-dv igor-dv merged commit c25731f into storybookjs:master May 7, 2018
@Hypnosphi
Copy link
Member

released as 4.0.0-alpha.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants