Skip to content

Commit

Permalink
chore: cleanup dead code (#21340)
Browse files Browse the repository at this point in the history
* chore: cleanup dead code

* fix

* fix

* fix tests
  • Loading branch information
tgriesser committed May 6, 2022
1 parent de2e99d commit 1ed93ff
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 69 deletions.
5 changes: 0 additions & 5 deletions packages/data-context/src/DataContext.ts
Expand Up @@ -366,10 +366,6 @@ export class DataContext {
])
}

get loader () {
return this.util.loader
}

/**
* Resets all of the state for the data context,
* so we can initialize fresh for each E2E test
Expand All @@ -392,7 +388,6 @@ export class DataContext {
return Promise.all([
this.lifecycleManager.destroy(),
this.cloud.reset(),
this.util.disposeLoaders(),
this.actions.project.clearCurrentProject(),
this.actions.dev.dispose(),
])
Expand Down
2 changes: 1 addition & 1 deletion packages/data-context/src/sources/HtmlDataSource.ts
Expand Up @@ -35,7 +35,7 @@ export class HtmlDataSource {
)
} catch (e) {
err = e
await this.ctx.util.delayMs(1000)
await new Promise((resolve) => setTimeout(resolve, 1000))
}
}

Expand Down
6 changes: 1 addition & 5 deletions packages/data-context/src/sources/ProjectDataSource.ts
Expand Up @@ -357,10 +357,6 @@ export class ProjectDataSource {
return preferences[projectTitle] ?? null
}

frameworkLoader = this.ctx.loader<string, typeof WIZARD_FRAMEWORKS[number] | null>((projectRoots) => {
return Promise.all(projectRoots.map((projectRoot) => Promise.resolve(this.guessFramework(projectRoot))))
})

private guessFramework (projectRoot: string) {
const guess = WIZARD_FRAMEWORKS.find((framework) => {
const lookingForDeps = framework.detectors.map((x) => x.package).reduce(
Expand All @@ -379,7 +375,7 @@ export class ProjectDataSource {

const looseComponentGlob = '*.{js,jsx,ts,tsx,.vue}'

const framework = await this.frameworkLoader.load(this.ctx.currentProject)
const framework = this.guessFramework(this.ctx.currentProject)

return {
component: framework?.glob ?? looseComponentGlob,
Expand Down
9 changes: 0 additions & 9 deletions packages/data-context/src/sources/SettingsDataSource.ts

This file was deleted.

45 changes: 0 additions & 45 deletions packages/data-context/src/sources/UtilDataSource.ts
@@ -1,5 +1,3 @@
import DataLoader from 'dataloader'
import crypto from 'crypto'
import fetch from 'cross-fetch'
import type { DataContext } from '../DataContext'

Expand All @@ -15,49 +13,6 @@ const { agent } = require('@packages/network')
export class UtilDataSource {
constructor (private ctx: DataContext) {}

private _allLoaders: DataLoader<any, any>[] = []

async settleAll<T> (promises: Promise<T>[]) {
const vals = await Promise.allSettled(promises)

return vals.map((v) => v.status === 'fulfilled' ? v.value : this.ensureError(v.reason))
}

/**
* Utility for a promise delay, in milliseconds
*/
async delayMs (ms: number) {
await new Promise((resolve) => setTimeout(resolve, ms))
}

assertAbsolute (val: string) {
if (!this.ctx.path.isAbsolute(val)) {
throw new Error(`Expected ${val} to be an absolute path`)
}
}

ensureError (val: any): Error {
return val instanceof Error ? val : new Error(val)
}

loader = <K, V, C = K>(batchLoadFn: DataLoader.BatchLoadFn<K, V>) => {
const loader = new DataLoader<K, V, C>(batchLoadFn, { cache: false })

this._allLoaders.push(loader)

return loader
}

disposeLoaders () {
for (const loader of this._allLoaders) {
loader.clearAll()
}
}

sha1 (value: string) {
return crypto.createHash('sha1').update(value).digest('hex')
}

fetch (input: RequestInfo | URL, init?: RequestInit) {
// @ts-ignore agent isn't a part of cross-fetch's API since it's not a part of the browser's fetch but it is a part of node-fetch
// which is what will be used here
Expand Down
1 change: 0 additions & 1 deletion packages/data-context/src/sources/index.ts
Expand Up @@ -10,7 +10,6 @@ export * from './GitDataSource'
export * from './HtmlDataSource'
export * from './MigrationDataSource'
export * from './ProjectDataSource'
export * from './SettingsDataSource'
export * from './UtilDataSource'
export * from './VersionsDataSource'
export * from './WizardDataSource'
Expand Down
Expand Up @@ -221,7 +221,8 @@ describe('code-generator', () => {
target,
}

sinon.stub(ctx.project.frameworkLoader, 'load').resolves(WIZARD_FRAMEWORKS[0])
// @ts-ignore
sinon.stub(ctx.project, 'guessFramework').returns(WIZARD_FRAMEWORKS[0])

const newSpecCodeGenOptions = new SpecOptions(ctx, {
codeGenPath: path.join(__dirname, 'files', 'react', 'Button.jsx'),
Expand All @@ -243,7 +244,8 @@ describe('code-generator', () => {
target,
}

sinon.stub(ctx.project.frameworkLoader, 'load').resolves(WIZARD_FRAMEWORKS[1])
// @ts-ignore
sinon.stub(ctx.project, 'guessFramework').returns(WIZARD_FRAMEWORKS[1])

const newSpecCodeGenOptions = new SpecOptions(ctx, {
codeGenPath: path.join(__dirname, 'files', 'vue', 'Button.vue'),
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend-shared/cypress/e2e/e2ePluginSetup.ts
Expand Up @@ -341,7 +341,7 @@ async function makeE2ETasks () {
return { value }
} catch (e: any) {
if (i <= retries) {
await ctx.util.delayMs(obj.options.retryDelay ?? 1000)
await new Promise((resolve) => setTimeout(resolve, obj.options.retryDelay ?? 1000))
}

lastErr = e
Expand Down

3 comments on commit 1ed93ff

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 1ed93ff May 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.0.0/linux-x64/10.0-release-1ed93ffebd446532e3df1b50913a60874b4c6ef1/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 1ed93ff May 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.0.0/darwin-x64/10.0-release-1ed93ffebd446532e3df1b50913a60874b4c6ef1/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 1ed93ff May 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the win32 x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.0.0/win32-x64/10.0-release-1ed93ffebd446532e3df1b50913a60874b4c6ef1/cypress.tgz

Please sign in to comment.