Skip to content

Commit

Permalink
Integrate Karma Infrastructure (#48)
Browse files Browse the repository at this point in the history
# Pull Request

## 🤨 Rationale

Introduces karma test infrastructure for writing unit tests. Modeled after the integration in [fast foundation](https://github.com/microsoft/fast/blob/e92c9e5197e54fc5c6ec6daaf36c09d9190c7ef2/packages/web-components/fast-foundation/karma.conf.js).

This does not integrate the playwright-based FAST e2e testing framework.

## 👩‍💻 Implementation

Migrated a similar karma configuration as used in FAST with some differences:
- Using jasmine for the BDD framework instead of mocha to match Web Chapter recommendations
- Switched to Webpack 5 to align with storybook and Angular integrations. Fast is using Webpack 4 but has been working on [migrating to Webpack 5](microsoft/fast#4736).
- Does not integrate Fast's approach to code coverage due to [lack of webpack 5 support in one of the istanbul plugins](webpack-contrib/istanbul-instrumenter-loader#110).

Some other minor refactors included in this change:
- Created an eslint config at the root to lint config js files for karma, storybook, etc. Currently disabled for storybook to address in a follow-up.
- Enabled the [`importsNotUsedAsValues`](https://www.typescriptlang.org/tsconfig#importsNotUsedAsValues) TypeScript compiler rule for nimble components. This is helpful as nimble components currently relies on side-effects of imports and as a result of enabling the rule it becomes explicit when an import is done for side-effects instead of just for type imports, ie `import './someFile';` (note how there are no named imports, just side-effects).

## 🧪 Testing

Included a sample test file for the Button based on existing FastFoundation tests. Does not represent what the Button tests should cover but is just used as an example to test the infrastructure. In a follow-up the example tests should be replaced with tests for Nimble Button specific features (currently just appearance configuration).
  • Loading branch information
rajsite authored Jul 29, 2021
1 parent ed1b8a3 commit c2ecbdd
Show file tree
Hide file tree
Showing 29 changed files with 817 additions and 87 deletions.
5 changes: 5 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
root = true

[*.yml]
indent_style = space
indent_size = 2

[*.md]
indent_style = space
indent_size = 4
21 changes: 11 additions & 10 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Contributing
# Contributing to Nimble

## Repository overview

Expand All @@ -19,19 +19,20 @@ This repository uses the following tooling. See below for more info.
## Getting Started

From the `nimble` directory:
1. Make sure you have npm version 7+ installed by running `npm --version`. If you have npm version 6 or earlier, upgrade by running `npm install npm@latest -g`.
1. Run `npm install`
1. Run `npm run build`
1. Run `npm run storybook -w @ni/nimble-components` to view the components in Storybook
- Note: **you'll need to refresh your browser window to see style changes**.
1. Make sure you have npm version 7+ installed by running `npm --version`. If you have npm version 6 or earlier, upgrade by running `npm install npm@latest -g`.
1. Run `npm install`
1. Run `npm run build`
1. Run `npm run storybook -w @ni/nimble-components` to view the components in Storybook

**Note**: You will need to refresh your browser window to see style changes made in source.

## Develop New Components

### Adding a new component

1. Ensure UX specs are up to date and tokens are generated. [See instructions for contributing to nimble tokens](packages/nimble-tokens/CONTRIBUTING.md).
1. Expose any tokens in the token provider and add web component logic. [See instructions for contributing to nimble components](packages/nimble-components/CONTRIBUTING.md).
1. Add wrappers for each framework. [See instructions for adding Angular wrappers](angular-workspace/projects/ni/nimble-angular/CONTRIBUTING.md). [See instructions for adding Blazor wrappers](packages/nimble-blazor/CONTRIBUTING.md).
1. Ensure UX specs are up to date and tokens are generated. See instructions for [contributing to nimble tokens](packages/nimble-tokens/CONTRIBUTING.md).
1. Expose any tokens in the token provider and add web component logic. See instructions for [contributing to nimble components](packages/nimble-components/CONTRIBUTING.md).
1. Add wrappers for each framework. See instructions for [adding Angular wrappers](angular-workspace/projects/ni/nimble-angular/CONTRIBUTING.md). See instructions for [adding Blazor wrappers](packages/nimble-blazor/CONTRIBUTING.md).
1. Publish and use! 🎉

## Pull Requests, Releases, and Versioning
Expand All @@ -54,7 +55,7 @@ Install packages using the workflow you would expect for npm workspaces and a sl

### NPM packages

To install npm packages start from the root of the repository and use `npm install <my-package> --workspace=path/to/target`.
To install npm packages start from the root of the repository and use `npm install <new-package> --workspace=<target-package-name>`.

Example: Install `five` in an npm workspace project:

Expand Down
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ Consult the `README.md` for each package to learn more, including how to use it
### Quick Start

From the `nimble` directory:
1. Make sure you have npm version 7+ installed by running `npm --version`. If you have npm version 6 or earlier, upgrade by running `npm install npm@latest -g`.
1. Run `npm install`
1. Run `npm run build`
1. Run `npm run storybook -w @ni/nimble-components` to view the components in Storybook.
- Note: **you'll need to refresh your browser window to see style changes**.
1. Make sure you have npm version 7+ installed by running `npm --version`. If you have npm version 6 or earlier, upgrade by running `npm install npm@latest -g`.
1. Run `npm install`
1. Run `npm run build`
1. Run `npm run storybook -w @ni/nimble-components` to view the components in Storybook

**Note**: You will need to refresh your browser window to see style changes made in source.

Follow the instructions in [CONTRIBUTING.md](CONTRIBUTING.md) to modify the design system.
4 changes: 2 additions & 2 deletions angular-workspace/projects/ni/nimble-angular/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Contributing
# Contributing to Nimble Angular

TODO
TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "Docs update",
"packageName": "@ni/nimble-angular",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "Docs update",
"packageName": "@ni/nimble-angular-schematics",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Karma unit test infrastructure integration",
"packageName": "@ni/nimble-components",
"email": "[email protected]",
"dependentChangeType": "prerelease"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "Docs update",
"packageName": "@ni/nimble-tokens",
"email": "[email protected]",
"dependentChangeType": "none"
}
108 changes: 108 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/nimble-angular-schematics/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Contributing
# Contributing to Nimble Angular Schematics

TODO
2 changes: 1 addition & 1 deletion packages/nimble-blazor/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Contributing
# Contributing to Nimble Blazor

TODO
29 changes: 8 additions & 21 deletions packages/nimble-components/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
module.exports = {
extends: [
'@ni/eslint-config/typescript',
'@ni/eslint-config/typescript-requiring-type-checking'
],
parserOptions: {
project: './tsconfig.json',
tsconfigRootDir: __dirname
},
rules: {
// *-default-export lines can be deleted once a fix for this issue is published and uptaken
// https://github.com/ni/javascript-styleguide/issues/39
'import/prefer-default-export': 'off',
'import/no-default-export': 'error'
},
overrides: [{
files: ['*.stories.ts'],
rules: {
'import/no-extraneous-dependencies': ['error', { devDependencies: true }],
'import/no-default-export': 'off'
}
}]
root: true,
extends: '@ni',
ignorePatterns: [
// TODO enable and lint storybook js
// '!/.storybook',
'node_modules',
'dist'
]
};
Loading

0 comments on commit c2ecbdd

Please sign in to comment.