-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from thadeu/feat/support-to-multi-root-folders
added support to multi-root projects
- Loading branch information
Showing
11 changed files
with
534 additions
and
331 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
.vscode/** | ||
.vscode-test/** | ||
out/test/** | ||
out/**/*.map | ||
out/spec/** | ||
# out/**/*.map | ||
src/** | ||
.gitignore | ||
tsconfig.json | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import { describe, expect, test } from 'vitest' | ||
import FileObject from '../src/FileObject' | ||
|
||
describe('#toJSON', () => { | ||
test('with rails app spec file', () => { | ||
let filepath = 'spec/controllers/aliquots_controller_spec.rb' | ||
let object = new FileObject(filepath, { integration: 'rails', folder: 'spec', suffix: 'spec' }) | ||
|
||
let result = object.toJSON() | ||
|
||
expect(object.isLibrary(filepath)).toBe(false) | ||
expect(object.isExpectation(filepath)).toBe(true) | ||
|
||
expect(result.name).toBe('controllers/aliquots_controller_spec.rb') | ||
expect(result.ext).toBe('.rb') | ||
expect(result.namespace).toBe('spec') | ||
expect(result.suffix).toBe('spec') | ||
|
||
expect(result.isRailsApp).toBe(true) | ||
expect(result.inversePath).toBe('app/controllers/aliquots_controller.rb') | ||
expect(result.specPath).toBe('spec/controllers/aliquots_controller_spec.rb') | ||
}) | ||
|
||
test('with rails app file', () => { | ||
let filepath = 'app/controllers/aliquots_controller.rb' | ||
let object = new FileObject(filepath, { integration: 'rails', folder: 'spec', suffix: 'spec' }) | ||
|
||
let result = object.toJSON() | ||
|
||
expect(object.isLibrary(filepath)).toBe(false) | ||
expect(object.isExpectation(filepath)).toBe(false) | ||
|
||
expect(result.name).toBe('controllers/aliquots_controller.rb') | ||
expect(result.ext).toBe('.rb') | ||
expect(result.namespace).toBe('app') | ||
expect(result.suffix).toBe(undefined) | ||
|
||
expect(result.isRailsApp).toBe(true) | ||
expect(result.inversePath).toBe('spec/controllers/aliquots_controller_spec.rb') | ||
expect(result.specPath).toBe('spec/controllers/aliquots_controller_spec.rb') | ||
}) | ||
|
||
test('with library file', () => { | ||
let filepath = 'lib/send_sms.rb' | ||
let object = new FileObject(filepath, { integration: 'rails', folder: 'spec', suffix: 'spec' }) | ||
|
||
let result = object.toJSON() | ||
|
||
expect(object.isLibrary(filepath)).toBe(true) | ||
expect(object.isExpectation(filepath)).toBe(false) | ||
|
||
expect(result.name).toBe('lib/send_sms.rb') | ||
expect(result.ext).toBe('.rb') | ||
expect(result.namespace).toBe('lib') | ||
expect(result.suffix).toBe(undefined) | ||
|
||
expect(result.isRailsApp).toBe(true) | ||
expect(result.inversePath).toBe('spec/lib/send_sms_spec.rb') | ||
expect(result.specPath).toBe('spec/lib/send_sms_spec.rb') | ||
}) | ||
|
||
test('with library spec file', () => { | ||
let filepath = 'spec/lib/send_sms.rb' | ||
let object = new FileObject(filepath, { integration: 'rails', folder: 'spec', suffix: 'spec' }) | ||
|
||
let result = object.toJSON() | ||
|
||
expect(object.isLibrary(filepath)).toBe(true) | ||
expect(object.isExpectation(filepath)).toBe(true) | ||
|
||
expect(result.name).toBe('lib/send_sms.rb') | ||
expect(result.ext).toBe('.rb') | ||
expect(result.namespace).toBe('spec') | ||
expect(result.suffix).toBe(undefined) | ||
|
||
expect(result.isRailsApp).toBe(true) | ||
expect(result.inversePath).toBe('spec/lib/send_sms_spec.rb') | ||
expect(result.specPath).toBe('spec/lib/send_sms_spec.rb') | ||
}) | ||
|
||
test('when workspace use spec file', () => { | ||
let filepath = 'test/lib/complete_account_test.rb' | ||
|
||
let object = new FileObject(filepath, { integration: 'other', folder: 'test', suffix: 'test' }) | ||
let result = object.toJSON() | ||
|
||
expect(object.isLibrary(filepath)).toBe(true) | ||
expect(object.isExpectation(filepath)).toBe(true) | ||
|
||
expect(result.name).toBe('lib/complete_account_test.rb') | ||
expect(result.ext).toBe('.rb') | ||
expect(result.namespace).toBe('test') | ||
expect(result.suffix).toBe('test') | ||
|
||
expect(result.isRailsApp).toBe(false) | ||
expect(result.inversePath).toBe('lib/complete_account.rb') | ||
expect(result.specPath).toBe('test/lib/complete_account_test.rb') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { describe, expect, test } from 'vitest' | ||
import WorkSpace from '../src/WorkSpace' | ||
|
||
const railsConfig = { integration: 'rails', folder: 'spec', suffix: 'spec' } | ||
|
||
describe('#toJSON', () => { | ||
test('when workspace is one folder', () => { | ||
let fileUri = '/Users/thadeu/code/opensource-community/todo-bcdd/app/models/todo/item/complete.rb' | ||
|
||
const workSpace = new WorkSpace(fileUri) | ||
const project = workSpace.toJSON() | ||
const file = workSpace.fromFileUri(railsConfig) | ||
|
||
expect(project.uri).toBe('Users/thadeu/code/opensource-community/todo-bcdd') | ||
expect(project.name).toBe('todo-bcdd') | ||
expect(file.path).toBe('app/models/todo/item/complete.rb') | ||
}) | ||
|
||
test('when workspace is two folder', () => { | ||
let fileUri = '/Users/thadeu/code/opensource-community/todo-bcdd/app/models/todo/item/complete.rb' | ||
|
||
const workSpace = new WorkSpace(fileUri) | ||
const project = workSpace.toJSON() | ||
const file = workSpace.fromFileUri(railsConfig) | ||
|
||
expect(project.uri).toBe('Users/thadeu/code/opensource-community/todo-bcdd') | ||
expect(project.name).toBe('todo-bcdd') | ||
expect(file.path).toBe('app/models/todo/item/complete.rb') | ||
}) | ||
|
||
test('when workspace use spec file', () => { | ||
let fileUri = '/Users/thadeu/code/opensource-community/todo-bcdd/spec/models/todo/item/complete_spec.rb' | ||
|
||
const workSpace = new WorkSpace(fileUri) | ||
const project = workSpace.toJSON() | ||
const file = workSpace.fromFileUri(railsConfig) | ||
|
||
expect(project.uri).toBe('Users/thadeu/code/opensource-community/todo-bcdd') | ||
expect(project.name).toBe('todo-bcdd') | ||
expect(file.path).toBe('spec/models/todo/item/complete_spec.rb') | ||
}) | ||
|
||
test('when workspace use spec file', () => { | ||
let fileUri = '/Users/thadeu/code/opensource-community/todo-bcdd/test/models/todo/item/complete_test.rb' | ||
|
||
const config = { integration: 'rails', folder: 'test', suffix: 'test' } | ||
const workSpace = new WorkSpace(fileUri) | ||
const project = workSpace.toJSON() | ||
const file = workSpace.fromFileUri(config) | ||
|
||
expect(project.uri).toBe('Users/thadeu/code/opensource-community/todo-bcdd') | ||
expect(project.name).toBe('todo-bcdd') | ||
expect(file.path).toBe('test/models/todo/item/complete_test.rb') | ||
}) | ||
|
||
test('when workspace use spec file', () => { | ||
let fileUri = '/Users/thadeu/code/opensource-community/packwerk/test/lib/complete_account_test.rb' | ||
|
||
const workSpace = new WorkSpace(fileUri) | ||
const project = workSpace.toJSON() | ||
const file = workSpace.fromFileUri({ integration: 'other', folder: 'test', suffix: 'test' }) | ||
|
||
expect(project.uri).toBe('Users/thadeu/code/opensource-community/packwerk') | ||
expect(project.name).toBe('packwerk') | ||
expect(file.path).toBe('test/lib/complete_account_test.rb') | ||
}) | ||
|
||
test('when workspace use spec file', () => { | ||
let fileUri = '/Users/thadeu/code/opensource-community/packwerk/lib/complete_account.rb' | ||
|
||
const workSpace = new WorkSpace(fileUri) | ||
const project = workSpace.toJSON() | ||
const file = workSpace.fromFileUri({ integration: 'other', folder: 'test', suffix: 'test' }) | ||
|
||
expect(project.uri).toBe('Users/thadeu/code/opensource-community/packwerk') | ||
expect(project.name).toBe('packwerk') | ||
expect(file.path).toBe('lib/complete_account.rb') | ||
expect(file.specPath).toBe('test/lib/complete_account_test.rb') | ||
}) | ||
|
||
test('when workspace use spec file', () => { | ||
let fileUri = '/Users/thadeu/code/atendesimples/atendesimples-app/spec/controllers/advanced_configurations_controller_spec.rb' | ||
|
||
const workSpace = new WorkSpace(fileUri) | ||
const project = workSpace.toJSON() | ||
const file = workSpace.fromFileUri(railsConfig) | ||
|
||
expect(project.uri).toBe('Users/thadeu/code/atendesimples/atendesimples-app') | ||
expect(project.name).toBe('atendesimples-app') | ||
expect(file.path).toBe('spec/controllers/advanced_configurations_controller_spec.rb') | ||
expect(file.specPath).toBe('spec/controllers/advanced_configurations_controller_spec.rb') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
export const EXTENSION_NAME = 'vscode-run-rspec-file' | ||
export const SETTINGS_RSPEC_COMMAND_KEY = `${EXTENSION_NAME}.custom-command` | ||
export const SETTINGS_RSPEC_FOLDER = `${EXTENSION_NAME}.folder` | ||
export const SETTINGS_RSPEC_CONTROLLER_FOLDER = `${EXTENSION_NAME}.controller-spec-directory` | ||
export const SETTINGS_SUFFIX_FILE = `${EXTENSION_NAME}.suffix` | ||
export const SETTINGS_INTEGRATION_TYPE = `${EXTENSION_NAME}.integration` | ||
|
||
export type SettingsType = { | ||
customCommand?: any | ||
folder?: any | ||
suffix?: any | ||
controllerFolder?: any | ||
integration?: any | ||
} | ||
|
||
export const SETTINGS_DEFAULT: SettingsType = { | ||
customCommand: 'bundle exec rspec', | ||
folder: 'spec', | ||
suffix: 'spec', | ||
controllerFolder: 'controllers', | ||
integration: 'rails', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import path from 'node:path' | ||
import compact from 'lodash.compact' | ||
|
||
type FileObjectType = { | ||
namespace?: string | ||
name?: string | ||
suffix?: string | ||
ext?: string | ||
path?: string | ||
inversePath?: string | ||
specPath?: string | ||
isRailsApp?: boolean | ||
} | ||
|
||
export default class FileObject { | ||
filepath: string | ||
|
||
config: { | ||
suffix: string | ||
folder: string | ||
integration: string | ||
} | ||
|
||
constructor(filepath?: string, config?: any) { | ||
this.filepath = filepath | ||
this.config = config || {} | ||
} | ||
|
||
static fromRelativeUri(filepath?: string, config?: any): FileObjectType { | ||
return new FileObject(filepath, config).toJSON() | ||
} | ||
|
||
isExpectation = (text: string) => /^(spec|test)/.test(text) | ||
|
||
isLibrary = (text: string) => /lib/.test(text) | ||
|
||
isRailsApp = () => this.config?.integration == 'rails' | ||
|
||
toJSON(): FileObjectType { | ||
let parts = compact(this.filepath.split(path.sep)) | ||
|
||
let namespace = parts[0] | ||
let name = parts.slice(1).join('/') | ||
|
||
let ext = name.match(/(?<ext>\.rb)$/)?.groups?.ext | ||
let suffix = name.match(/(\w+_)(?<suffix>spec|test)\.rb$/)?.groups?.suffix | ||
let filepath = [namespace, name].join('/') | ||
|
||
if (this.isLibrary(namespace)) { | ||
name = parts.join('/') | ||
} | ||
|
||
let result = { | ||
namespace, | ||
name, | ||
suffix, | ||
ext, | ||
path: filepath, | ||
inversePath: '', | ||
specPath: '', | ||
isRailsApp: this.isRailsApp(), | ||
} | ||
|
||
if (this.isExpectation(suffix)) { | ||
let nameWithoutSuffix = name.replace(new RegExp(`_${suffix}`), '') | ||
|
||
if (this.isLibrary(filepath)) { | ||
result.inversePath = ['lib', nameWithoutSuffix].join('/').replace(/^(lib\/)(lib)/, '$2') | ||
} else { | ||
result.inversePath = ['app', nameWithoutSuffix].join('/').replace(/^(app\/)(app)/, '$2') | ||
} | ||
} else { | ||
let nameByMode = this.isRailsApp() ? name : filepath | ||
let nameWithSuffix = nameByMode.replace('.rb', `_${this.config?.suffix}.rb`) | ||
|
||
result.inversePath = compact([this.config?.folder, nameWithSuffix]).join('/') | ||
} | ||
|
||
result.specPath = this.isExpectation(suffix) ? result.path : result.inversePath | ||
|
||
return result | ||
} | ||
} |
Oops, something went wrong.