Skip to content

Commit

Permalink
feat!: migrate to native esm
Browse files Browse the repository at this point in the history
- set "type": "module"
- upgrade to chai@5 and rest of matchers
- single dist output
- redo tsconfig.json using [email protected] template
- bump syntax to es2023
  • Loading branch information
AviVahl committed Dec 15, 2024
1 parent 31d8106 commit 6235935
Show file tree
Hide file tree
Showing 12 changed files with 238 additions and 161 deletions.
299 changes: 194 additions & 105 deletions package-lock.json

Large diffs are not rendered by default.

36 changes: 18 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
{
"name": "test-drive",
"version": "1.6.0",
"type": "module",
"description": "Opinionated library for writing web component tests",
"main": "./cjs/index.js",
"module": "./esm/index.js",
"types": "./esm/index.d.ts",
"exports": {
".": "./dist/index.js",
"./package.json": "./package.json"
},
"scripts": {
"clean": "rimraf ./cjs ./esm",
"clean": "rimraf ./dist",
"prebuild": "npm run clean",
"build": "npm run build:cjs && npm run build:esm",
"build:cjs": "tsc -p tsconfig.build.json --outDir cjs --module commonjs",
"build:esm": "tsc -p tsconfig.build.json --outDir esm --module esnext",
"build": "tsc",
"pretest": "npm run typecheck && npm run lint",
"test": "mocha-web \"./test/**/*.spec.ts\"",
"test": "mocha-web \"./src/test/**/*.spec.ts\"",
"lint": "eslint",
"typecheck": "tsc --noEmit",
"prepack": "npm run build"
},
"dependencies": {
"chai": "^4.5.0",
"chai-as-promised": "^7.1.2",
"chai": "^5.1.2",
"chai-as-promised": "^8.0.1",
"chai-dom": "^1.12.0",
"chai-style": "^1.0.3",
"dom-matches": "^2.0.0",
"promise-assist": "^2.0.1",
"sinon": "^19.0.2",
"sinon-chai": "^3.7.0"
"sinon-chai": "^4.0.0"
},
"devDependencies": {
"@playwright/browser-chromium": "^1.49.1",
"@types/chai": "^4.3.20",
"@types/chai-as-promised": "^7.1.8",
"@types/chai": "^5.0.1",
"@types/chai-as-promised": "^8.0.1",
"@types/chai-dom": "^1.11.3",
"@types/chai-style": "^1.0.2",
"@types/dom-matches": "^2.0.2",
"@types/mocha": "^10.0.10",
"@types/sinon": "^17.0.3",
"@types/sinon-chai": "^3.2.12",
"@types/sinon-chai": "^4.0.0",
"esbuild": "^0.24.0",
"eslint": "^9.16.0",
"eslint": "^9.17.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-no-only-tests": "^3.3.0",
"mocha": "^11.0.1",
Expand All @@ -49,10 +49,10 @@
"typescript-eslint": "^8.18.0"
},
"files": [
"cjs",
"esm",
"dist",
"src",
"matchers.d.ts"
"matchers.d.ts",
"!*/test"
],
"repository": {
"type": "git",
Expand Down
10 changes: 0 additions & 10 deletions pleb.config.mjs

This file was deleted.

14 changes: 7 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
/// <reference path="../matchers.d.ts" preserve="true" />

import sinon from 'sinon';
import chai from 'chai';
import * as chai from 'chai';
import chaiDom from 'chai-dom';
import isPresent from './is-present';
import isPresent from './is-present.js';
import chaiAsPromised from 'chai-as-promised';
import chaiStyle from 'chai-style';
import sinonChai from 'sinon-chai';
import layout from './layout';
import layout from './layout.js';

export * from 'promise-assist';

Expand All @@ -24,9 +24,9 @@ if (typeof window !== 'undefined') {

const expect: Chai.ExpectStatic = Object.assign(chai.expect.bind(chai), chai.expect);

export * from './helpers';
export * from './layout';
export * from './layout-driver';
export * from './select-dom';
export * from './helpers.js';
export * from './layout.js';
export * from './layout-driver.js';
export * from './select-dom.js';

export { chai, sinon, expect, layout };
2 changes: 1 addition & 1 deletion src/is-present.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isElement } from './helpers';
import { isElement } from './helpers.js';

function isPresent(element: unknown): boolean {
return (
Expand Down
2 changes: 1 addition & 1 deletion src/layout.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isElement } from './helpers';
import { isElement } from './helpers.js';

interface Point {
x: number;
Expand Down
2 changes: 1 addition & 1 deletion test/is-present.spec.ts → src/test/is-present.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from '../src';
import { expect } from '../index.js';

describe('isPresent() matcher detects', function () {
this.timeout(5_000);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect, generateMap, dom, type Geometry } from '../src';
import { expect, generateMap, dom, type Geometry } from '../index.js';

describe('Layout test driver', function () {
const source = `
Expand Down
2 changes: 1 addition & 1 deletion test/layout.spec.ts → src/test/layout.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access */

import { expect, getLayoutFixture, detectMisalignment } from '../src';
import { expect, getLayoutFixture, detectMisalignment } from '../index.js';

describe('Layout matchers', function () {
describe('detect placement', function () {
Expand Down
2 changes: 1 addition & 1 deletion test/select-dom.spec.ts → src/test/select-dom.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { selectDom, expect } from '../src';
import { selectDom, expect } from '../index.js';

function textContent(element: Element | null) {
return element && element.textContent;
Expand Down
4 changes: 0 additions & 4 deletions tsconfig.build.json

This file was deleted.

24 changes: 13 additions & 11 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */

/* Language and Environment */
"target": "es2020", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
"lib": ["es2020", "dom", "dom.iterable"], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
"target": "es2023", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
"lib": ["es2023", "dom", "dom.iterable"], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
// "jsx": "preserve", /* Specify what JSX code is generated. */
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
Expand All @@ -25,20 +25,22 @@
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */

/* Modules */
"module": "esnext", /* Specify what module code is generated. */
"module": "node16", /* Specify what module code is generated. */
// "rootDir": "./", /* Specify the root folder within your source files. */
"moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
"moduleResolution": "node16", /* Specify how TypeScript looks up a file from a given module specifier. */
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
"types": ["mocha"], /* Specify type package names to be included without being referenced in a source file. */
"types": ["mocha"], /* Specify type package names to be included without being referenced in a source file. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
// "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
// "rewriteRelativeImportExtensions": true, /* Rewrite '.ts', '.tsx', '.mts', and '.cts' file extensions in relative import paths to their JavaScript equivalent in output files. */
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
// "noUncheckedSideEffectImports": true, /* Check side effect imports. */
// "resolveJsonModule": true, /* Enable importing .json files. */
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
Expand All @@ -54,28 +56,27 @@
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
"sourceMap": true, /* Create source map files for emitted JavaScript files. */
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
// "noEmit": true, /* Disable emitting files from a compilation. */
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
// "outDir": "./", /* Specify an output folder for all emitted files. */
"outDir": "./dist", /* Specify an output folder for all emitted files. */
// "removeComments": true, /* Disable emitting comments. */
// "noEmit": true, /* Disable emitting files from a compilation. */
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
"newLine": "lf", /* Set the newline character for emitting files. */
// "newLine": "crlf", /* Set the newline character for emitting files. */
// "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */

/* Interop Constraints */
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
// "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
"verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
// "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
Expand All @@ -88,6 +89,7 @@
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
// "strictBuiltinIteratorReturn": true, /* Built-in iterators are instantiated with a 'TReturn' type of 'undefined' instead of 'any'. */
// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
Expand Down

0 comments on commit 6235935

Please sign in to comment.