Skip to content

Commit 582af0c

Browse files
committed
fix(#431): Run example tests
1 parent 8562ae1 commit 582af0c

31 files changed

+247
-84
lines changed

packages/cli/config/jest.config.js

+25-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,37 @@
1+
import fs from 'node:fs';
2+
import { findUp, findUpStop } from 'find-up';
3+
4+
let rootDir;
5+
6+
await findUp(directory => {
7+
const candidatePath = `${directory}/node_modules/@tybalt/test-utils/dist/cjs/setup.js`;
8+
if (fs.existsSync(candidatePath)) {
9+
rootDir = directory;
10+
return findUpStop;
11+
} else {
12+
return candidatePath;
13+
}
14+
});
15+
116
export default {
217
moduleFileExtensions: ['js', 'ts'],
318
extensionsToTreatAsEsm: ['.ts'],
419
transform: {
5-
'^.+\\.ts$': [
20+
'^.+\\.m?[tj]sx?$': [
621
'ts-jest',
722
{
8-
useESM: true,
23+
useESM: true
924
},
1025
],
26+
'\\.(css|less|sass|scss)$': `${rootDir}/node_modules/@tybalt/cli/config/style-mock.js`
1127
},
1228
testEnvironment: 'jest-environment-jsdom',
13-
setupFilesAfterEnv: [`@tybalt/test-utils/dist/cjs/setup.js`],
29+
setupFilesAfterEnv: [
30+
`${rootDir}/node_modules/@tybalt/test-utils/dist/cjs/setup.js`
31+
],
1432
rootDir: process.cwd(),
33+
transformIgnorePatterns: [
34+
'/node_modules/(?!(@tybalt)/)',
35+
`${rootDir}/packages/test-utils`,
36+
],
1537
};

packages/cli/config/style-mock.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default {
2+
process: function() {
3+
return { code: "" };
4+
}
5+
};

packages/cli/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@
3535
"eslint": "^8.56.0",
3636
"find-up": "^7.0.0",
3737
"glob": "^10.3.10",
38+
"identity-obj-proxy": "3.0.0",
3839
"import-meta-resolve": "^4.0.0",
40+
"jest-css-modules-transform": "^4.4.2",
3941
"jest-environment-jsdom": "^29.7.0",
4042
"js-convert-case": "^4.2.0",
4143
"mkdirp": "^3.0.1",

packages/cli/src/commands/test.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export default ({ program }: CommandContext) => {
1313
.action(async (pattern: string) => {
1414
const __filename = url.fileURLToPath(import.meta.url);
1515
const __dirname = path.dirname(__filename);
16+
1617
const filePath = path.resolve(`${__dirname}../../../config/jest.config.js`);
1718

1819
const results = child_process.spawnSync(
@@ -21,12 +22,13 @@ export default ({ program }: CommandContext) => {
2122
{},
2223
);
2324

24-
const stdErr = results.stderr.toString();
25+
const stdErr = results.stderr?.toString();
2526

26-
console.log(results.stdout.toString());
27+
console.log(results.stdout?.toString());
2728
if (stdErr) {
2829
console.error(stdErr);
29-
process.exit(1);
3030
}
31+
32+
process.exit(results.status || 0);
3133
});
3234
};

packages/cli/tsconfig.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
"$schema": "https://json.schemastore.org/tsconfig",
33
"compilerOptions": {
44
"baseUrl": ".",
5-
"lib": ["es2021", "dom"],
5+
"lib": ["es2022", "dom"],
66
"module": "nodenext",
7-
"target": "es2021",
7+
"target": "es2022",
88
"outDir": "dist",
99
"strict": true,
1010
"esModuleInterop": true,

packages/core/package.json

+10-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,22 @@
22
"name": "@tybalt/core",
33
"version": "0.1.4",
44
"description": "A library for writing web components",
5-
"module": "dist/mjs/index.js",
5+
"module": "dist/mjs/index.mjs",
66
"main": "dist/cjs/index.js",
7+
"types": "dist/types/index.d.ts",
8+
"exports": {
9+
".": {
10+
"import": "./dist/mjs/index.mjs",
11+
"require": "./dist/cjs/index.js",
12+
"types": "./dist/types/index.d.ts"
13+
}
14+
},
715
"scripts": {
816
"build": "yarn run compile && yarn run generate-types",
917
"ci-test": "jest --coverage",
1018
"clean": "rimraf dist/",
1119
"compile": "yarn run compile-esm && yarn run compile-commonjs",
12-
"compile-esm": "esbuild src/index.ts --bundle --format=esm --outfile=dist/mjs/index.js",
20+
"compile-esm": "esbuild src/index.ts --bundle --format=esm --platform=browser --target=es2022 --outfile=dist/mjs/index.mjs",
1321
"compile-commonjs": "esbuild src/index.ts --bundle --format=cjs --outfile=dist/cjs/index.js",
1422
"debug": "yarn node --inspect-brk $(yarn bin jest) --runInBand",
1523
"generate-types": "tsc && rsync -a dist/types/ dist/mjs/ && rsync -a dist/types/ dist/cjs/",

packages/core/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export { default as forceRerenderOnUpdate } from './api/force-rerender-on-update
77
export { default as html } from './api/html';
88
export { default as createContext } from './api/create-context';
99
export { default as ContextEvent } from './api/context-event';
10+
export { default as render } from './api/render';
1011

1112
/*
1213
* It seems that esbuild doesn't parse the dependency graph to determine a correct ordering of the modules, so we

packages/core/tsconfig.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
"$schema": "https://json.schemastore.org/tsconfig",
33
"compilerOptions": {
44
"baseUrl": ".",
5-
"lib": ["es2021", "dom"],
5+
"lib": ["es2022", "dom"],
66
"module": "node16",
7-
"target": "es2021",
7+
"target": "es2022",
88
"outDir": "dist/types",
99
"strict": true,
1010
"esModuleInterop": true,

packages/core/tst/integration/events.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe('events', () => {
1313
return html`<div><button @click="${listener}"></button></div>`;
1414
},
1515
setup(_, { emit }) {
16-
const listener = (evt) => {
16+
const listener = (evt: Event) => {
1717
evt.stopPropagation();
1818

1919
emit(eventName);

packages/esbuild-plugin/tsconfig.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
"$schema": "https://json.schemastore.org/tsconfig",
33
"compilerOptions": {
44
"baseUrl": ".",
5-
"lib": ["es2021"],
5+
"lib": ["es2022"],
66
"module": "nodenext",
7-
"target": "es2021",
7+
"target": "es2022",
88
"outDir": "dist/types",
99
"strict": true,
1010
"esModuleInterop": true,

packages/eslint-plugin/src/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ module.exports = {
55
configs: {
66
recommended: {
77
parserOptions: {
8-
ecmaVersion: 2021,
8+
ecmaVersion: 2022,
99
},
1010
plugins: ['@tybalt/eslint-plugin'],
11-
env: { browser: true, es2021: true },
11+
env: { browser: true, es2022: true },
1212
extends: ['eslint:recommended'],
1313
rules: {
1414
'@tybalt/component-names-are-multi-word': 'error',
@@ -17,7 +17,7 @@ module.exports = {
1717
'ts-recommended': {
1818
plugins: ['@typescript-eslint', '@tybalt/eslint-plugin'],
1919
parser: '@typescript-eslint/parser',
20-
env: { browser: true, es2021: true },
20+
env: { browser: true, es2022: true },
2121
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
2222
rules: {
2323
'@tybalt/component-names-are-multi-word': 'error',

packages/eslint-plugin/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"compilerOptions": {
3-
"target": "es2021",
3+
"target": "es2022",
44
"module": "nodenext",
55
"sourceMap": false,
66
"outDir": "dist",

packages/example/jest.config.js

-10
This file was deleted.

packages/example/jest.setup.js

-8
This file was deleted.

packages/example/package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
"type": "module",
88
"scripts": {
99
"build": "tybalt build",
10-
"ci-test": "echo 'TODO: run tybalt test --integration'",
11-
"examples": "tybalt examples",
10+
"clean": "rimraf dist/",
11+
"ci-test": "yarn run test",
1212
"lint": "tybalt lint",
1313
"scaffold": "tybalt scaffold",
14-
"test": "echo 'TODO: run tybalt test'",
14+
"test": "tybalt test",
1515
"watch": "tybalt watch 'src/**/*.*'",
1616
"serve": "tybalt serve",
17-
"prepare": "yarn run build && yarn run lint && yarn run test && yarn run examples"
17+
"prepare": "yarn run build && yarn run lint && yarn run test"
1818
},
1919
"keywords": [],
2020
"author": "Douglas Wade <[email protected]>",
@@ -29,7 +29,7 @@
2929
"browser-sync": "^3.0.2",
3030
"esbuild": "^0.19.10",
3131
"esbuild-jest": "^0.5.0",
32-
"jest-environment-jsdom": "^29.7.0"
32+
"rimraf": "^5.0.5"
3333
},
3434
"bugs": {
3535
"url": "https://github.com/doug-wade/tybalt/issues?q=is%3Aissue+is%3Aopen+label%3Aexample"

packages/example/src/Button/button.test.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { mount } from '@tybalt/test-utils';
2-
import Button from './button.component';
2+
3+
import Button from './button.component.ts';
34

45
describe('button', () => {
56
it('renders a button', async () => {

packages/example/src/CookieBanner/cookie-banner.component.ts

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ export default defineComponent({
2222
},
2323
setup(_: PropsStateMap, ctx: SetupContext) {
2424
const clickHandler = () => {
25-
console.log('got click!');
2625
ctx.emit('click');
2726
};
2827

packages/example/src/CookieBanner/cookie-banner.test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { mount } from '@tybalt/test-utils';
2-
import CookieBanner from './cookie-banner.component';
2+
3+
import CookieBanner from './cookie-banner.component.ts';
34

45
const mountCookieBanner = async () => {
56
const wrapper = await mount(CookieBanner);
@@ -16,14 +17,13 @@ describe('cookie banner', () => {
1617
expect(actual.attributes('href')).toBe('http://www.example.com');
1718
});
1819

19-
it.skip('emits a click event when the button is clicked', async () => {
20+
it('emits a click event when the button is clicked', async () => {
2021
const wrapper = await mountCookieBanner();
2122

22-
const actual = wrapper.find('button');
23+
const actual = wrapper.find('example-button');
2324
actual.trigger('click');
2425

25-
// TODO: Enable as part of #64
26-
// expect(wrapper.emitted('click')).toHaveLength(1);
26+
expect(wrapper.emitted('click')).toHaveLength(1);
2727
});
2828

2929
it('has a primary button', async () => {

packages/example/src/Link/link.test.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { mount } from '@tybalt/test-utils';
2-
import Link from './link.component';
2+
3+
import Link from './link.component.ts';
34

45
const href = 'http://www.example.com';
56
const slot = '<div slot="content">mock slot value</div>';

packages/example/tsconfig.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
{
22
"$schema": "https://json.schemastore.org/tsconfig",
33
"compilerOptions": {
4-
"lib": ["es2021", "dom"],
4+
"allowJs": true,
5+
"allowImportingTsExtensions": true,
6+
"lib": ["es2022", "dom"],
57
"module": "nodenext",
6-
"target": "es2021",
8+
"target": "es2022",
79
"outDir": "dist",
810
"strict": true,
911
"esModuleInterop": true,

packages/parser/tsconfig.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"$schema": "https://json.schemastore.org/tsconfig",
33
"compilerOptions": {
4-
"lib": ["es2021", "dom"],
4+
"lib": ["es2022", "dom"],
55
"module": "nodenext",
6-
"target": "es2021",
6+
"target": "es2022",
77
"outDir": "dist",
88
"strict": true,
99
"esModuleInterop": true,

packages/reactive/package.json

+10-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,22 @@
22
"name": "@tybalt/reactive",
33
"version": "0.1.4",
44
"description": "A library for managing reactivity with proxies",
5-
"module": "dist/mjs/index.js",
5+
"module": "dist/mjs/index.mjs",
66
"main": "dist/cjs/index.js",
7+
"types": "dist/types/index.d.ts",
8+
"exports": {
9+
".": {
10+
"import": "./dist/mjs/index.mjs",
11+
"require": "./dist/cjs/index.js",
12+
"types": "./dist/types/index.d.ts"
13+
}
14+
},
715
"scripts": {
816
"build": "yarn run compile && yarn run generate-types",
917
"ci-test": "jest --coverage",
1018
"clean": "rimraf dist/",
1119
"compile": "yarn run compile-esm && yarn run compile-commonjs",
12-
"compile-esm": "esbuild src/index.ts --bundle --format=esm --outfile=dist/mjs/index.js",
20+
"compile-esm": "esbuild src/index.ts --bundle --format=esm --platform=browser --target=es2022 --outfile=dist/mjs/index.mjs",
1321
"compile-commonjs": "esbuild src/index.ts --bundle --format=cjs --outfile=dist/cjs/index.js",
1422
"debug": "yarn node --inspect-brk $(yarn bin jest) --runInBand",
1523
"generate-types": "tsc && rsync -a dist/types/ dist/mjs/ && rsync -a dist/types/ dist/cjs/",

packages/reactive/tsconfig.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
"$schema": "https://json.schemastore.org/tsconfig",
33
"compilerOptions": {
44
"baseUrl": ".",
5-
"lib": ["es2021", "dom"],
5+
"lib": ["es2022", "dom"],
66
"module": "node16",
7-
"target": "es2021",
7+
"target": "es2022",
88
"outDir": "dist/types",
99
"strict": true,
1010
"esModuleInterop": true,

packages/test-utils-lit-example/tsconfig.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
{
22
"$schema": "https://json.schemastore.org/tsconfig",
33
"display": "Node 16",
4-
54
"compilerOptions": {
6-
"lib": ["es2021"],
5+
"lib": ["es2022"],
76
"module": "nodenext",
8-
"target": "es2021",
7+
"target": "es2022",
98
"experimentalDecorators": true,
109
"strict": true,
1110
"esModuleInterop": true,

packages/test-utils/jest.config.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ module.exports = {
66
},
77
moduleNameMapper: {
88
'#src/(.*)': '<rootDir>/src/$1',
9+
// Force module uuid to resolve with the CJS entry point, because Jest does not support package.json.exports. See https://github.com/uuidjs/uuid/issues/451
10+
"uuid": require.resolve('uuid'),
911
},
1012
testEnvironment: 'jest-environment-jsdom',
11-
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
13+
setupFilesAfterEnv: ['<rootDir>/jest.setup.js']
1214
};

0 commit comments

Comments
 (0)