Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cypress tooling #10406

Merged
merged 1 commit into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class CypressModuleFactory {
private static final JHipsterDestination CYPRESS_DESTINATION = to(CYPRESS_TEST);

private static final String PRIMARY_APP = "common/primary/app";
private static final String UTILS = "utils";

private static final String CYPRESS_EXCLUSION = "\"src/test/javascript/integration/**/*.ts\"";
private static final String EXCLUDE_KEY = "\"exclude\"";
Expand Down Expand Up @@ -64,6 +65,10 @@ public JHipsterModule buildModule(JHipsterModuleProperties properties) {
SOURCE.append(CYPRESS_TEST).append(PRIMARY_APP).file("Home.spec.ts"),
CYPRESS_DESTINATION.append(PRIMARY_APP).append("Home.spec.ts")
)
.batch(SOURCE.append(CYPRESS_TEST).append(UTILS), CYPRESS_DESTINATION.append(UTILS))
.addFile("Interceptor.ts")
.addFile("DataSelector.ts")
.and()
.and()
.optionalReplacements()
.in(path("tsconfig.json"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { defineConfig } from 'cypress';
export default defineConfig({
e2e: {
baseUrl: 'http://localhost:9000',
specPattern: 'src/test/javascript/integration/**/*.spec.ts',
specPattern: 'src/test/javascript/integration/**/*.(spec|cy).ts',
fixturesFolder: false,
supportFile: false,
video: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"lib": ["es5", "es6", "dom", "dom.iterable"],
"types": ["cypress"]
},
"include": ["**/*.spec.ts"]
"include": ["**/*.ts"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const dataSelector = (selector: string): string => `[data-selector="${selector}"]`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { HttpResponseInterceptor, RouteMatcher, StaticResponse } from 'cypress/types/net-stubbing';

type ResponseSender = {
send: () => void;
};

const createDeferredPromise = (): [Promise<void>, () => void] => {
let resolvePromise: () => void = () => {};

const promise = new Promise<void>(resolve => {
resolvePromise = resolve;
});

return [promise, resolvePromise];
};

/**
* Intercepts a request indefinitely until `send` is called.
* @param requestMatcher - The criteria to match the request.
* @param response - The response to send when resolved.
* @param alias - An optional alias for the intercepted request.
* @returns An object with a `send` method to trigger the response.
*/
export const interceptForever = (
requestMatcher: RouteMatcher,
response?: StaticResponse | HttpResponseInterceptor,
alias?: string,
): ResponseSender => {
const [deferredPromise, resolveDeferredPromise] = createDeferredPromise();

cy.intercept(requestMatcher, request =>
deferredPromise.then(() => {
request.reply(response);
}),
).as(alias || 'request');

return { send: resolveDeferredPromise };
};
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ private static JHipsterModuleAsserter assertCypressModule(ModuleFile... files) {
.containing("baseUrl: 'http://localhost:9000',")
.and()
.hasPrefixedFiles("src/test/javascript/integration", ".eslintrc.cjs", "tsconfig.json")
.hasFiles("src/test/javascript/integration/common/primary/app/Home.spec.ts");
.hasFiles("src/test/javascript/integration/common/primary/app/Home.spec.ts")
.hasPrefixedFiles("src/test/javascript/integration/utils", "Interceptor.ts", "DataSelector.ts");
}
}