Skip to content

Commit

Permalink
Clean up a bunch of TypeScript shenanigans
Browse files Browse the repository at this point in the history
Some of this was remnants of the past. Some was me not quite
understanding script vs. module. Some was me misunderstanding what was
actually going on in Tsd.

It turns out that Tsd was just incidentally working, but I was never
using it according to their intentions. You don't really test *.ts files
with Tsd [1], but I happen to place compile output along side of them,
hence "incidentally working".

Now I am merely relying on TS compiler's diagnostic output, which is
really what Tsd does anyway.

[1] tsdjs/tsd#32
  • Loading branch information
badeball committed Apr 27, 2023
1 parent 2e7665a commit 82ad333
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 66 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
**/*.d.ts
!examples/**/*
!features/**/*
!cucumber.d.ts
!cucumber.js
!augmentations.d.ts
!declarations.d.ts
!types/index.d.ts

# Temporary directory for test execution
tmp/
37 changes: 37 additions & 0 deletions augmentations.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import messages from "@cucumber/messages";

import { Registry } from "./lib/registry";

declare module "@cucumber/cucumber" {
interface IWorld {
tmpDir: string;
verifiedLastRunError: boolean;
lastRun: {
stdout: string;
stderr: string;
output: string;
exitCode: number;
};
}
}

declare global {
namespace globalThis {
var __cypress_cucumber_preprocessor_dont_use_this: true | undefined;

var __cypress_cucumber_preprocessor_registry_dont_use_this:
| Registry
| undefined;
}

interface Window {
testState: {
gherkinDocument: messages.GherkinDocument;
pickles: messages.Pickle[];
pickle: messages.Pickle;
pickleStep?: messages.PickleStep;
};
}
}

export {};
14 changes: 0 additions & 14 deletions cucumber.d.ts

This file was deleted.

12 changes: 0 additions & 12 deletions lib/add-cucumber-preprocessor-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,6 @@ import { ensureIsAbsolute } from "./helpers/paths";

import { createTimestamp } from "./messages-helpers";

/**
* Work-around for the fact that some Cypress versions pre v10 were missing this property in their types.
*/
declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace Cypress {
interface PluginConfigOptions {
testFiles: string[];
}
}
}

function memoize<T extends (...args: any[]) => any>(
fn: T
): (...args: Parameters<T>) => ReturnType<T> {
Expand Down
8 changes: 0 additions & 8 deletions lib/create-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,6 @@ import { generateSnippet } from "./snippets";

import { runStepWithLogGroup } from "./cypress";

declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace globalThis {
// eslint-disable-next-line no-var
var __cypress_cucumber_preprocessor_dont_use_this: true | undefined;
}
}

type Node = ReturnType<typeof parse>;

interface CompositionContext {
Expand Down
13 changes: 0 additions & 13 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import messages from "@cucumber/messages";

import DataTable from "./data_table";

import {
Expand All @@ -8,17 +6,6 @@ import {
IStepDefinitionBody,
} from "./types";

declare global {
interface Window {
testState: {
gherkinDocument: messages.GherkinDocument;
pickles: messages.Pickle[];
pickle: messages.Pickle;
pickleStep?: messages.PickleStep;
};
}
}

export { resolve as resolvePreprocessorConfiguration } from "./preprocessor-configuration";

export {
Expand Down
12 changes: 1 addition & 11 deletions lib/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,16 +229,6 @@ export class Registry {
}
}

declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace globalThis {
// eslint-disable-next-line no-var
var __cypress_cucumber_preprocessor_registry_dont_use_this:
| Registry
| undefined;
}
}

const globalPropertyName =
"__cypress_cucumber_preprocessor_registry_dont_use_this";

Expand All @@ -261,7 +251,7 @@ export function freeRegistry() {
delete globalThis[globalPropertyName];
}

export function getRegistry() {
export function getRegistry(): Registry {
return assertAndReturn(
globalThis[globalPropertyName],
"Expected to find a global registry (this usually means you are trying to define steps or hooks in support/e2e.js, which is not supported)"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"test": "npm run test:fmt && npm run test:lint && npm run test:types && npm run test:unit && npm run test:integration",
"test:fmt": "prettier --ignore-path .gitignore --check '**/*.ts'",
"test:lint": "eslint .",
"test:types": "tsd",
"test:types": "tsc -p test-d",
"test:unit": "mocha lib/**/*.test.ts",
"test:run-all-specs": "mocha --timeout 0 test/run-all-specs.ts",
"test:integration": "cucumber-js",
Expand Down
2 changes: 0 additions & 2 deletions lib/index.test-d.ts → test-d/methods.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { expectType } from "tsd";

import messages from "@cucumber/messages";

import "./";

import {
Given,
When,
Expand Down
11 changes: 11 additions & 0 deletions test-d/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"noEmit": true
},
"include": [
"*.test-d.ts",
"../augmentations.d.ts",
"../declarations.d.ts",
]
}
5 changes: 2 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@
},
"include": [
"lib/**/*.ts",
"test/**/*.ts",
"methods.ts",
"augmentations.d.ts",
"declarations.d.ts",
"browserify.ts",
"esbuild.ts",
"webpack.ts"
],
"exclude": ["lib/index.test-d.ts"]
]
}

0 comments on commit 82ad333

Please sign in to comment.