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

Fix test deletions #454

Merged
merged 3 commits into from
Aug 3, 2021
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
12 changes: 7 additions & 5 deletions src/commands/app/delete/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ class DeleteActionCommand extends BaseCommand {
const folder = fs.statSync(action.path).isFile() ? path.dirname(action.path) : action.path
fs.removeSync(folder)
aioLogger.debug(`deleted '${folder}'`)
// delete test files
// NOTE: those paths are not always correct, but removeSync doesn't throw in case the file does not exist
// NOTE: (attempt) to delete test files. The test file must match the action name
// file in the same folder, which is true in most cases, but won't work for asset compute action tests for example.
try {
const pathToE2eTests = path.join('e2e', action.actionsDir, action.actionName + '.e2e.js')
const pathToUnitTests = path.join('test', action.actionsDir, action.actionName + '.test.js')
const pathToE2eTests = path.join(action.e2eTestsDir, action.actionName + '.e2e.js')
const pathToUnitTests = path.join(action.unitTestsDir, action.actionName + '.test.js')
fs.removeSync(pathToE2eTests)
aioLogger.debug(`deleted '${pathToE2eTests}'`)
fs.removeSync(pathToUnitTests)
Expand Down Expand Up @@ -125,7 +125,9 @@ class DeleteActionCommand extends BaseCommand {
actionsDir: path.relative(implConfig.root, implConfig.actions.src),
name: fullActionName,
actionName,
configData
configData,
unitTestsDir: implConfig.tests.unit,
e2eTestsDir: implConfig.tests.e2e
}
actions.push(actionObj)
actionsByImpl[implName].push(actionObj)
Expand Down
9 changes: 8 additions & 1 deletion src/commands/app/delete/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,20 @@ class DeleteExtensionCommand extends BaseCommand {

deleteImplementations (configs) {
Object.entries(configs).forEach(([id, c]) => {
// delete actions
if (c.app.hasBackend) {
fs.removeSync(c.actions.src)
}
// delete web-assets
if (c.app.hasFrontend) {
fs.removeSync(c.web.src)
}

// delete test files
fs.removeSync(c.tests.unit)
fs.removeSync(c.tests.e2e)

// delete config
// try to find another config file => case of init extension in another folder
const configKey = id === 'application' ? 'application' : `extensions.${id}`
const configDataOp = this.getConfigFileForKey(configKey + '.operations')
Expand All @@ -90,7 +98,6 @@ class DeleteExtensionCommand extends BaseCommand {
// delete config in parent config file
const configData = this.getConfigFileForKey(configKey)
deleteUserConfig(configData)
// todo delete tests !
})
}
}
Expand Down
24 changes: 18 additions & 6 deletions test/commands/app/delete/action.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ const mockConfigData = {
actions: {
src: 'actions'
},
tests: {
unit: 'test',
e2e: 'e2e'
},
runtimeManifest: {
packages: {
pkga: {
Expand Down Expand Up @@ -205,25 +209,29 @@ describe('good flags', () => {
name: 'a',
path: 'a-path',
actionsDir: 'a-dir',
actionName: 'a-fileName'
actionName: 'a-fileName',
unitTestsDir: path.normalize('A/unit/tests/dir'),
e2eTestsDir: path.normalize('A/e2e/tests/dir')
}, {
name: 'b',
path: 'b-path',
actionsDir: 'b-dir',
actionName: 'b-fileName'
actionName: 'b-fileName',
unitTestsDir: path.normalize('B/unit/tests/dir'),
e2eTestsDir: path.normalize('B/e2e/tests/dir')
}]
command.getAllActions = () => {
return { actions: fakeActions, actionsByImpl: { } }
}
await command.run()
expect(fs.removeSync).toHaveBeenCalledWith('a-path')
expect(fs.removeSync).toHaveBeenCalledWith(path.normalize('e2e/a-dir/a-fileName.e2e.js'))
expect(fs.removeSync).toHaveBeenCalledWith(path.normalize('test/a-dir/a-fileName.test.js'))
expect(fs.removeSync).toHaveBeenCalledWith(path.normalize('A/e2e/tests/dir/a-fileName.e2e.js'))
expect(fs.removeSync).toHaveBeenCalledWith(path.normalize('A/unit/tests/dir/a-fileName.test.js'))
// expect(command.log).toHaveBeenCalledWith('✔ Deleted \'a\'')

expect(fs.removeSync).toHaveBeenCalledWith('b-path')
expect(fs.removeSync).toHaveBeenCalledWith(path.normalize('e2e/b-dir/b-fileName.e2e.js'))
expect(fs.removeSync).toHaveBeenCalledWith(path.normalize('test/b-dir/b-fileName.test.js'))
expect(fs.removeSync).toHaveBeenCalledWith(path.normalize('B/e2e/tests/dir/b-fileName.e2e.js'))
expect(fs.removeSync).toHaveBeenCalledWith(path.normalize('B/unit/tests/dir/b-fileName.test.js'))
// expect(command.log).toHaveBeenCalledWith('✔ Deleted \'b\'')
})

Expand Down Expand Up @@ -296,6 +304,10 @@ describe('getAllActions', () => {
actions: {
src: 'action-src'
},
tests: {
unit: 'test',
e2e: 'e2e'
},
root: 'root',
manifest: {
full: {
Expand Down
18 changes: 18 additions & 0 deletions test/commands/app/delete/extension.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ describe('good args', () => {
},
web: {
src: 'fake-web-source-path'
},
tests: {
unit: 'test',
e2e: 'e2e'
}
}
})
Expand All @@ -145,6 +149,8 @@ describe('good args', () => {
expect(fs.removeSync).toHaveBeenCalledWith('file-to-delete')
expect(fs.removeSync).toHaveBeenCalledWith('fake-action-source-path')
expect(fs.removeSync).toHaveBeenCalledWith('fake-web-source-path')
expect(fs.removeSync).toHaveBeenCalledWith('test')
expect(fs.removeSync).toHaveBeenCalledWith('e2e')
expect(deleteUserConfig).toHaveBeenCalledWith({ data: 'configData' })
})

Expand All @@ -161,6 +167,10 @@ describe('good args', () => {
},
actions: {
src: 'fake-action-source-path'
},
tests: {
unit: 'test',
e2e: 'e2e'
}
}
})
Expand All @@ -169,6 +179,8 @@ describe('good args', () => {
expect(fs.removeSync).toHaveBeenCalledWith('file-to-delete')
expect(fs.removeSync).toHaveBeenCalledWith('fake-action-source-path')
expect(fs.removeSync).not.toHaveBeenCalledWith('fake-web-source-path')
expect(fs.removeSync).toHaveBeenCalledWith('test')
expect(fs.removeSync).toHaveBeenCalledWith('e2e')
expect(deleteUserConfig).toHaveBeenCalledWith({ data: 'configData' })
})

Expand All @@ -185,6 +197,10 @@ describe('good args', () => {
},
web: {
src: 'fake-web-source-path'
},
tests: {
unit: 'test',
e2e: 'e2e'
}
}
})
Expand All @@ -193,6 +209,8 @@ describe('good args', () => {
expect(fs.removeSync).toHaveBeenCalledWith('file-to-delete')
expect(fs.removeSync).not.toHaveBeenCalledWith('fake-action-source-path')
expect(fs.removeSync).toHaveBeenCalledWith('fake-web-source-path')
expect(fs.removeSync).toHaveBeenCalledWith('test')
expect(fs.removeSync).toHaveBeenCalledWith('e2e')
expect(deleteUserConfig).toHaveBeenCalledWith({ data: 'configData' })
})
})