Skip to content

Commit

Permalink
feat: update unit tests to latest
Browse files Browse the repository at this point in the history
Removed htmlhint (way outdated, caused node depreccation warning).
May add markuplint in future.
Removed less. Low usage, and very easy for users to add to their
project if they need.
Removed browser-do+jasmine, browser-do+mocha, since almost nobody
uses browser-do. Just provide jest/vitest for unit tests.
  • Loading branch information
3cp committed Aug 10, 2024
1 parent 25d44a2 commit 2c68524
Show file tree
Hide file tree
Showing 30 changed files with 86 additions and 373 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
47 changes: 18 additions & 29 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,27 @@
// @if mocha
import { expect } from 'chai';
// @endif
// @if vitest
import { describe, it, expect } from 'vitest';
// @endif
// @if shadow-dom
import { CustomElement } from 'aurelia';
// @endif
import { render } from './helper';
import { MyApp } from '../src/my-app';
import { createFixture } from '@aurelia/testing';
// @if jest
import { bootstrapTestEnvironment } from './setup';

beforeAll(bootstrapTestEnvironment);
// @endif

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, startPromise, stop } = createFixture(
'<my-app></my-app>',
{},
[MyApp],
);

try {
await startPromise;
assertText('Hello World!', { compact: true });
} finally {
await stop(true);
}
});
});
6 changes: 0 additions & 6 deletions common/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@
"es6": 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.

16 changes: 16 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,16 @@
import { BrowserPlatform } from '@aurelia/platform-browser';
import { setPlatform } from '@aurelia/testing';

// Sets up the Aurelia environment for testing
// @if vitest
const platform = new BrowserPlatform(window);
setPlatform(platform);
BrowserPlatform.set(globalThis, platform);
// @endif
// @if jest
export function bootstrapTestEnvironment() {
const platform = new BrowserPlatform(window);
setPlatform(platform);
BrowserPlatform.set(globalThis, platform);
}
// @endif
9 changes: 0 additions & 9 deletions common/test__if_not_no-unit-tests/setup.ext__if_ava

This file was deleted.

63 changes: 6 additions & 57 deletions dumber/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,15 @@ const devServer = require('./dev-server');
// @if css-module
const cssModule = require('gulp-dumber-css-module');
// @endif
// @if less
const less = require('gulp-less');
// @endif
// @if sass
const sass = require('gulp-dart-sass');
const sassPackageImporter = require('node-sass-package-importer');
// @endif
const postcss = require('gulp-postcss');
const autoprefixer = require('autoprefixer');
const postcssUrl = require('postcss-url');
// @if jasmine || mocha
const gulpRun = require('gulp-run');
// @endif

const isProduction = process.env.NODE_ENV === 'production';
const isTest = process.env.NODE_ENV === 'test';
const dist = 'dist';

// Read more in https://dumber.js.org
Expand All @@ -58,16 +51,6 @@ const dr = dumber({
// dumber-module-loader is injected automatically by dumber bundler after prepends.
// prepend: [],

// @if jasmine || mocha
// append after amd loader and all module definitions in entry bundle.
append: [
// Kick off all test files.
// Note dumber-module-loader requirejs call accepts regex which loads all matched module ids!
// Note all module ids are relative to dumber option "src" (default to 'src') folder.
isTest && "requirejs([/^\\.\\.\\/test\\/.+\\.spec$/]);"
],
// @endif

// Explicit dependencies, can use either "deps" (short name) or "dependencies" (full name).
// deps: [],

Expand All @@ -88,8 +71,7 @@ const dr = dumber({
// for npm package file "node_modules/foo/bar.js", the package name is "foo"
// for npm package file "node_modules/@scoped/foo/bar.js", the package name is "@scoped/foo"

// Here we skip code splitting in test mode.
codeSplit: isTest ? undefined : function (moduleId, packageName) {
codeSplit: function (moduleId, packageName) {
// Here for any local src, put into app-bundle
if (!packageName) return 'app-bundle';
// The codeSplit func does not need to return a valid bundle name.
Expand All @@ -108,7 +90,7 @@ const dr = dumber({
// "other-bundle.js": "other-bundle.js"
// }
// If you turned on hash, you need this callback to update index.html
onManifest: isTest ? undefined : function (filenameMap) {
onManifest: function (filenameMap) {
// Update index.html entry.bundle.js with entry.bundle.hash...js
console.log('Update index.html with ' + filenameMap['entry.bundle.js']);
const indexHtml = fs.readFileSync('_index.html').toString()
Expand All @@ -123,7 +105,7 @@ function buildJs(src) {
const ts = typescript.createProject('tsconfig.json', { noEmitOnError: true });
// @endif
return gulp.src(src, { sourcemaps: !isProduction })
.pipe(gulpif(!isProduction && !isTest, plumber()))
.pipe(gulpif(!isProduction, plumber()))
.pipe(au2())
// @if babel
.pipe(babel());
Expand All @@ -135,7 +117,7 @@ function buildJs(src) {

function buildHtml(src) {
return gulp.src(src)
.pipe(gulpif(!isProduction && !isTest, plumber()))
.pipe(gulpif(!isProduction, plumber()))
// @if shadow-dom
// The other possible Shadow DOM mode is "closed".
// If you turn on "closed" mode, there will be difficulty to perform e2e
Expand All @@ -150,16 +132,12 @@ function buildHtml(src) {

function buildCss(src) {
return gulp.src(src, { sourcemaps: !isProduction })
// @if less
.pipe(gulpif(!isProduction && !isTest, plumber()))
.pipe(gulpif(f => f.extname === '.less', less()))
// @endif
// @if sass
.pipe(gulpif(
f => f.extname === '.scss',
// sassPackageImporter handles @import "~bootstrap"
// https://github.com/maoberlehner/node-sass-magic-importer/tree/master/packages/node-sass-package-importer
isProduction || isTest ?
isProduction ?
sass.sync({ quietDeps: true, importer: sassPackageImporter() }) :
sass.sync({ quietDeps: true, importer: sassPackageImporter() }).on('error', sass.logError)
))
Expand All @@ -180,34 +158,22 @@ function buildCss(src) {

function build() {
// Merge all js/css/html file streams to feed dumber.
// dumber knows nothing about .ts/.less/.scss/.md files,
// dumber knows nothing about .ts/.scss/.md files,
// gulp-* plugins transpiled them into js/css/html before
// sending to dumber.
return merge2(
gulp.src('src/**/*.json'),
// @if babel
// @if !jasmine && !mocha
buildJs('src/**/*.js'),
// @endif
// @if jasmine || mocha
buildJs(isTest ? '{src,test}/**/*.js' : 'src/**/*.js'),
// @endif
// @endif
// @if typescript
// @if !jasmine && !mocha
buildJs('src/**/*.ts'),
// @endif
// @if jasmine || mocha
buildJs(isTest ? '{src,test}/**/*.ts' : 'src/**/*.ts'),
// @endif
// @endif
buildHtml('src/**/*.html'),
// @if css
buildCss('src/**/*.css')
// @endif
// @if less
buildCss('src/**/*.{less,css}')
// @endif
// @if sass
buildCss('src/**/*.{scss,css}')
// @endif
Expand All @@ -220,12 +186,7 @@ function build() {
// https://github.com/terser-js/terser#terser-fast-minify-mode
// It's a good balance on size and speed to turn off compress.
.pipe(gulpif(isProduction, terser({ compress: false })))
// @if !jasmine && !mocha
.pipe(gulp.dest(dist, { sourcemaps: isProduction ? false : '.' }));
// @endif
// @if jasmine || mocha
.pipe(gulp.dest(dist, { sourcemaps: isProduction ? false : (isTest ? true : '.') }));
// @endif
}

function clean() {
Expand Down Expand Up @@ -261,18 +222,6 @@ function watch() {

const run = gulp.series(clean, serve, watch);

// @if jasmine || mocha
// Watch all files for rebuild and test.
function watchTest() {
gulp.watch('{src,test}/**/*', gulp.series(build, test));
}

function test() {
return gulpRun('npm run test:headless').exec();
}

exports['watch-test'] = watchTest;
// @endif
exports.build = build;
exports.clean = clean;
exports['clear-cache'] = clearCache;
Expand Down
Loading

0 comments on commit 2c68524

Please sign in to comment.