migrate aio to eslint as tslint has been deprecated, the migration is restricted to the aio app and its e2e tests and does not include the other tools, for such reason both tslint and codelyzer have not been removed (to be done in a next PR) some minor tweaks needed to be applied to the code so that it would adhere to the new ESLinting behaviour most TSLint rules have been substituted with their ESLint equivalent, with some exceptions: * [whitespace] does not have an ESLint equivalent (suggested to be handled by prettier) * [import-spacing] does not have an ESLint equivalent (suggested to be handled by prettier) * [ban] replaced with [no-restricted-syntax] as there is no (official/included) ESLint equivalent some rules have minor different behaviours compared to their TSLint counterparts: * @typescript-eslint/naming-convention: - typescript-eslint does not enforce uppercase for const only. * @typescript-eslint/no-unused-expressions: - The TSLint optional config "allow-new" is the default ESLint behavior and will no longer be ignored. * arrow-body-style: - ESLint will throw an error if the function body is multiline yet has a one-line return on it. * eqeqeq: - Option "smart" allows for comparing two literal values, evaluating the value of typeof and null comparisons. * no-console: - Custom console methods, if they exist, will no longer be allowed. * no-invalid-this: - Functions in methods will no longer be ignored. * no-underscore-dangle: - Leading and trailing underscores (_) on identifiers will now be ignored. * prefer-arrow/prefer-arrow-functions: - ESLint does not support allowing standalone function declarations. - ESLint does not support allowing named functions defined with the function keyword. * space-before-function-paren: - Option "constructor" is not supported by ESLint. - Option "method" is not supported by ESLint. additional notes: * the current typescript version used by the aio app is 4.3.5, which is not supported by typescript-eslint (the supported versions are >=3.3.1 and <4.3.0). this causes a warning message to appear during linting, this issue should likely/hopefully disappear in the future as typescript-eslint catches up * The new "no-console" rule is not completely equivalent to what we had prior the migration, this is because TSLint's "no-console" rule let you specify the methods you did not want to allow, whilst ESLint's "no-console" lets you specify the methods that you do want to allow, so and in order not to have a very long list of methods in the ESLint rule it's been decided for the time being to simply only allow the "log", "warn" and "error" methods * 4 dependencies have been added as they have been considered necessary (see: https://github.com/angular/angular/pull/42820#discussion_r669978232) extra: * the migration has been performed by following: https://github.com/angular-eslint/angular-eslint#migrating-an-angular-cli-project-from-codelyzer-and-tslin * more on typescript-eslint at: https://github.com/typescript-eslint/typescript-eslint PR Close #42820
71 lines
2.3 KiB
TypeScript
71 lines
2.3 KiB
TypeScript
import { browser, by, element, ElementFinder, ExpectedConditions } from 'protractor';
|
|
|
|
export class SitePage {
|
|
/** The base URL with the trailing `/` stripped off (if any). */
|
|
baseUrl = browser.baseUrl.replace(/\/$/, '');
|
|
|
|
/** All URLs found in the app's `sitemap.xml` (i.e. valid URLs tha should not be redirected). */
|
|
sitemapUrls: string[] = browser.params.sitemapUrls;
|
|
|
|
/** A list of legacy URLs that should be redirected to new URLs (in the form `[fromUrl, toUrl]`). */
|
|
legacyUrls: string[][] = browser.params.legacyUrls;
|
|
|
|
/**
|
|
* Enter a query into the search field.
|
|
*/
|
|
async enterSearch(query: string) {
|
|
const searchInput = element(by.css('input[type=search]'));
|
|
await searchInput.clear();
|
|
await searchInput.sendKeys(query);
|
|
}
|
|
|
|
/**
|
|
* Get the text content of the `aio-doc-viewer` element (in lowercase).
|
|
*/
|
|
async getDocViewerText() {
|
|
const docViewer = element(by.css('aio-doc-viewer'));
|
|
const text = await docViewer.getText();
|
|
return text.toLowerCase();
|
|
}
|
|
|
|
/**
|
|
* Get a list of text contents for all search result items found on the page.
|
|
*/
|
|
async getSearchResults() {
|
|
const results = element.all(by.css('.search-results li'));
|
|
await browser.wait(ExpectedConditions.presenceOf(results.first()), 8000);
|
|
return await results.map<string>(link => (link as ElementFinder).getText());
|
|
}
|
|
|
|
/**
|
|
* Navigate to a URL, disable animations, wait for Angular and unregister the ServiceWorker.
|
|
* (The SW is unregistered to ensure that subsequent requests are passed through to the server.)
|
|
*/
|
|
async goTo(url: string) {
|
|
await browser.get(url || this.baseUrl);
|
|
await browser.executeScript('document.body.classList.add(\'no-animations\')');
|
|
await browser.waitForAngular();
|
|
await this.unregisterSw();
|
|
}
|
|
|
|
/**
|
|
* Initialize the page object and get it ready for further requests.
|
|
*/
|
|
async init() {
|
|
// Make an initial request to unregister the ServiceWorker.
|
|
await this.goTo('');
|
|
}
|
|
|
|
/**
|
|
* Unregister the ServiceWorker (if registered).
|
|
*/
|
|
async unregisterSw() {
|
|
const unregisterSwFn = (cb: () => void) => navigator.serviceWorker
|
|
.getRegistrations()
|
|
.then(regs => Promise.all(regs.map(reg => reg.unregister())))
|
|
.then(cb);
|
|
|
|
await browser.executeAsyncScript(unregisterSwFn);
|
|
}
|
|
}
|