Skip to content

Commit

Permalink
Test: use memfs based VirtualFs in cypress
Browse files Browse the repository at this point in the history
This will allow to remove lots of mocks Cypress tests.
  • Loading branch information
warpdesign committed Jan 3, 2023
1 parent c7481f3 commit d6b198c
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 22 deletions.
13 changes: 13 additions & 0 deletions e2e/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"assert": "^2.0.0",
"cypress": "^10.11.0",
"fs": "^0.0.1-security",
"path-browserify": "^1.0.1",
"pm2": "^4.1.2",
"stream-browserify": "^3.0.0",
"swc-loader": "^0.2.3",
Expand Down
5 changes: 3 additions & 2 deletions e2e/webpack.config.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,9 @@ const baseConfig = {
path: _resolve(__dirname, 'build-e2e'),
},
externals: {
path: '{}',
// path: '{}',
net: '{}',
tls: '{}',
fs: '{}',
},
node: {
__dirname: false,
Expand All @@ -66,6 +65,7 @@ const baseConfig = {
// Add '.ts' and '.tsx' as resolvable extensions.
extensions: ['.ts', '.tsx', '.js', '.json', '.css'],
alias: {
fs: 'memfs',
$src: _resolve(__dirname, '../src'),
// TODO: use proper polyfills instead of incomplete custom ones
...aliases,
Expand All @@ -76,6 +76,7 @@ const baseConfig = {
stream: require.resolve('stream-browserify'),
assert: require.resolve('assert/'),
util: require.resolve('util/'),
path: require.resolve('path-browserify'),
},
},
module: {
Expand Down
19 changes: 2 additions & 17 deletions src/gui/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,8 @@ import child_process from 'child_process'

import { ExplorerApp } from '$src/components/App'
import { i18n } from '$src/locale/i18n'
// register Fs that will be available in React-Explorer
// I guess there is a better place to do that
import { FsWsl } from '$src/services/plugins/FsWsl'
import { FsLocal } from '$src/services/plugins/FsLocal'
import { FsGeneric } from '$src/services/plugins/FsGeneric'
import { registerFs } from '$src/services/Fs'
import { AppState } from '$src/state/appState'
import initFS from '$src/utils/initFS'

configure({
enforceActions: 'observed',
Expand All @@ -27,17 +22,6 @@ configure({
safeDescriptors: window.ENV.CY ? false : true,
})

// TODO: there should be an easy way to automatically register new FS
function initFS() {
if ((process && process.env && process.env.NODE_ENV === 'test') || window.ENV.CY || typeof jest !== 'undefined') {
registerFs(FsGeneric)
// registerFs(FsVirtual)
} else {
registerFs(FsWsl)
registerFs(FsLocal)
}
}

class App {
appState: AppState

Expand Down Expand Up @@ -65,6 +49,7 @@ class App {
if (window.ENV.NODE_ENV !== 'production') {
await this.createTestFolder()
}

initFS()

await this.appState.loadSettingsAndPrepareViews()
Expand Down
2 changes: 1 addition & 1 deletion src/services/Fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export function getFS(path: string): Fs {
const newfs = interfaces.find((filesystem) => filesystem.canread(path))
// if (!newfs) {
// newfs = FsGeneric;
// }
// `

return newfs
}
Expand Down
2 changes: 1 addition & 1 deletion src/services/plugins/FsVirtual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const SEP = path.sep

// Since nodeJS will translate unix like paths to windows path, when running under Windows
// we accept Windows style paths (eg. C:\foo...) and unix paths (eg. /foo or ./foo)
const virtualStart = /^\/virtual/
const virtualStart = /^\//
const isRoot = (isWin && /((([a-zA-Z]\:)(\\)*)|(\\\\))$/) || /^\/$/

const progressFunc = throttle((progress: (bytes: number) => void, bytesRead: number) => {
Expand Down
2 changes: 1 addition & 1 deletion src/state/appState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export class AppState {

for (const desc of views) {
console.log('adding view', desc.viewId, desc.path, window.ENV.CY)
this.addView(window.ENV.CY ? '' : desc.path, desc.viewId)
this.addView(desc.path, desc.viewId)
}

this.initViewState()
Expand Down

0 comments on commit d6b198c

Please sign in to comment.