Skip to content

Commit

Permalink
Merge pull request #110 from aurelia/unit-tests
Browse files Browse the repository at this point in the history
feat: update unit tests to latest
  • Loading branch information
3cp authored Aug 10, 2024
2 parents 25d44a2 + 88f374f commit ea72d5a
Show file tree
Hide file tree
Showing 32 changed files with 85 additions and 390 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ This will cause `npx` to download the `makes` tool, along with the `aurelia` sca

## Development

This scaffolding skeleton is in the early stage, not quite ready for adding features. We want to keep feature set manageable as Aurelia 2 is constantly evolving.

There are some tests for this skeleton, setup in package.json. (totally not required by makes)

## Unit tests
Expand Down
39 changes: 9 additions & 30 deletions app-min/test__if_not_no-unit-tests/my-app.spec.ext
Original file line number Diff line number Diff line change
@@ -1,38 +1,17 @@
// @if mocha
import { expect } from 'chai';
// @endif
// @if vitest
import { describe, it, expect } from 'vitest';
// @endif
// @if shadow-dom
import { CustomElement } from 'aurelia';
import { describe, it } from 'vitest';
// @endif
import { render } from './helper';
import { MyApp } from '../src/my-app';
import { createFixture } from '@aurelia/testing';

describe('my-app', () => {
it('should render message', async () => {
const node = (await render('<my-app></my-app>', MyApp)).firstElementChild;
// @if shadow-dom
// In Shadow DOM open mode, shadowRoot is also accessible through DOM API
// node.shadowRoot
// But only Aurelia API can access shadowRoot in both open and closed mode.
const shadowRoot = CustomElement.for(node).shadowRoot;
// @if babel
const text = shadowRoot.textContent;
// @endif
// @if typescript
const text = (shadowRoot as Node).textContent;
// @endif
// @endif
// @if !shadow-dom
const text = node.textContent;
// @endif
// @if jasmine || jest || vitest
expect(text.trim()).toBe('Hello World!');
// @endif
// @if mocha
expect(text.trim()).to.equal('Hello World!');
// @endif
const { assertText } = await createFixture(
'<my-app></my-app>',
{},
[MyApp],
).started;

assertText('Hello World!', { compact: true });
});
});
8 changes: 1 addition & 7 deletions common/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,9 @@
},

"env": {
"es6": true,
"es2024": true,
"browser": true,
"node": true,
// @if jasmine
"jasmine": true,
// @endif
// @if mocha
"mocha": true,
// @endif
// @if jest
"jest": true,
// @endif
Expand Down
12 changes: 0 additions & 12 deletions common/.htmlhintrc__skip-if-exists

This file was deleted.

3 changes: 0 additions & 3 deletions common/.stylelintrc.json__skip-if-exists
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
// @if sass
"stylelint-config-standard-scss",
// @endif
// @if less
"stylelint-config-standard-less",
// @endif
// @if css-module
"stylelint-config-css-modules"
// @endif
Expand Down
14 changes: 0 additions & 14 deletions common/README.md__skip-if-exists
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,4 @@ Run unit tests in watch mode.

npm run test:watch

// @if jasmine || mocha
Unit tests run in browser through [browser-do](https://github.com/3cp/browser-do). Please check scripts in `package.json` for more details.

By default, browser-do shuts down browser after tests. To keep browser window open for inspection, pass additional argument `-k` or `--keep-open`.

npm run build:test && browser-do -k /* @if jasmine */--jasmine/* @endif *//* @if mocha */--mocha/* @endif */ --browser chrome < dist/entry.bundle.js

// @if webpack
Unit tests in watch mode is executed through stand webpack watch mode and the help of [webpack-shell-plugin-next](https://github.com/s00d/webpack-shell-plugin-next).
// @endif
// @if dumber
Unit tests in watch mode is executed through standard `gulp.watch` with the help of [gulp-run](https://github.com/MrBoolean/gulp-run).
// @endif
// @endif
// @endif
19 changes: 1 addition & 18 deletions common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,16 @@
"devDependencies": {
"eslint": "^8.57.0",
"@aurelia/testing": /* @if latest */"latest"/* @endif *//* @if dev */"dev"/* @endif */,
"htmlhint": "^1.1.4",
"stylelint": "^16.3.1",
// @if css
"stylelint-config-standard": "^36.0.0",
// @endif
// @if less
"stylelint-config-standard-less": "^3.0.1",
// @endif
// @if sass
"stylelint-config-standard-scss": "^13.1.0",
// @endif
// @if css-module
"stylelint-config-css-modules": "^4.4.0",
// @endif
// @if jasmine || mocha
"browser-do": "^4.1.0",
// @endif
},
"scripts": {
"lint:js": "eslint src/* @if !no-unit-tests */ test/* @endif *//* @if playwright */ e2e/* @endif *//* @if typescript */ --ext .js,.ts/* @endif */",
Expand All @@ -54,17 +47,7 @@
// @if sass
"lint:css": "stylelint \"src/**/*.scss\"",
// @endif
// @if less
"lint:css": "stylelint \"src/**/*.less\"",
// @endif
"lint:html": "htmlhint -c .htmlhintrc src",
"lint": "npm run lint:js && npm run lint:html && npm run lint:css",
// @if jest
"lint": "npm run lint:js && npm run lint:css",
"pretest": "npm run lint",
// @endif
// @if jasmine || mocha
"test": "npm run test:headless",
"pretest": "npm run lint && npm run build:test",
// @endif
}
}
2 changes: 1 addition & 1 deletion common/src/main.ext__if_app
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { MyApp } from './my-app';
// They are for sharedStyles in shadowDOM.
// However, css files imported in other js/ts files are processed by style-loader.
// @endif
// import shared from './shared./* @if css */css/* @endif *//* @if less */less/* @endif *//* @if sass */scss/* @endif */';
// import shared from './shared./* @if css */css/* @endif *//* @if sass */scss/* @endif */';
// @endif

Aurelia
Expand Down
9 changes: 0 additions & 9 deletions common/src/resource.d.ts__if_typescript
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ declare module '*.module.css' {
const value: Record<string, string>;
export default value;
}
// @if less
declare module '*.module.less' {
const value: Record<string, string>;
export default value;
}
// @endif
// @if sass
declare module '*.module.scss' {
const value: Record<string, string>;
Expand All @@ -30,9 +24,6 @@ declare module '*.module.scss' {
// @endif
// @if !css-module
declare module '*.css';
// @if less
declare module '*.less';
// @endif
// @if sass
declare module '*.scss';
// @endif
Expand Down
11 changes: 0 additions & 11 deletions common/test__if_not_no-unit-tests/helper.ext

This file was deleted.

31 changes: 31 additions & 0 deletions common/test__if_not_no-unit-tests/setup.ext
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { BrowserPlatform } from '@aurelia/platform-browser';
import { setPlatform, onFixtureCreated/* @if typescript */, type IFixture/* @endif */ } from '@aurelia/testing';
// @if vitest
import { beforeAll, afterEach } from 'vitest';
// @endif

// Sets up the Aurelia environment for testing
function bootstrapTextEnv() {
const platform = new BrowserPlatform(window);
setPlatform(platform);
BrowserPlatform.set(globalThis, platform);
}

const fixtures/* @if typescript */: IFixture<object>[]/* @endif */ = [];
beforeAll(() => {
bootstrapTextEnv();
onFixtureCreated(fixture => {
fixtures.push(fixture);
});
});

afterEach(() => {
fixtures.forEach(async f => {
try {
await f.stop(true);
} catch {
// ignore
}
});
fixtures.length = 0;
});
9 changes: 0 additions & 9 deletions common/test__if_not_no-unit-tests/setup.ext__if_ava

This file was deleted.

Loading

0 comments on commit ea72d5a

Please sign in to comment.