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

Allow configuration from package.json or .scuri.json #32

Closed
7 of 8 tasks
gparlakov opened this issue Sep 15, 2019 · 12 comments
Closed
7 of 8 tasks

Allow configuration from package.json or .scuri.json #32

gparlakov opened this issue Sep 15, 2019 · 12 comments

Comments

@gparlakov
Copy link
Owner

gparlakov commented Sep 15, 2019

We'd like to be able to configure things like:

  • it name - i.e. now hard-coded default when <method> is called it should ...
  • jest/jasmine
  • ts version - with or without conditional types
  • default or Angular version tests - i.e. to call setup() in every test case or rely on TestBed plus inject and test-global value
  • autospy location
    etc.
    • allow config file (.scurirc, package.json, ..., --config cli arg for custom file)
    • config custom class template
    • config custom function template
    • respect config in test names
    • configure location of autospy
    • configure setup function name use custom templates for that
    • configure whether to add tests for new methods (per test file, per execution of scuri:spec) use custom templates for that
    • configure if try to add support for Angular Standard method (per test file, per execution of scuri:spec) use custom templates for that
@JarvisJ
Copy link

JarvisJ commented May 26, 2021

I'd like to be able to provide a custom spec template via a config option. For people/projects who want specific boilerplate, this would be very useful.

Edit - poking around angular-schematics and the scuri code a bit, I see this isn't necessarily as straightforward as I would've hoped. Maybe custom templates is more of a feature request for the schematics project.

@gparlakov
Copy link
Owner Author

@JarvisJ thanks for the feedback. I intend to look into that. Will let you know .

@gparlakov
Copy link
Owner Author

POC custom template

@JarvisJ I just published a POC for custom template* - scuri@1.0.8-rc.1
Please check it out. I'd appreciate feedback.

How to use:

npm i scuri@next
Windows path follows - turn the slashes if mac/linux
ng g scuri:spec --name .\src\app\app.component.ts --classTemplate .\src\template\my.tmpl

the my.tmpl file is the custom template* and

*custom class template - creates a spec for a class e.g. export class MyComponent{ ... and not export function myFunction() {...

@JarvisJ
Copy link

JarvisJ commented Jun 8, 2021

Awesome! I tried out 1.0.8-rc.1, and it worked as expected with my custom template. Thanks!

@gparlakov
Copy link
Owner Author

gparlakov commented Jun 8, 2021 via email

@gparlakov
Copy link
Owner Author

@JarvisJ 1.1.0-rc.1 is now live with support for config file. Care to take it for a spin?

@JarvisJ
Copy link

JarvisJ commented Jul 1, 2021

Works great so far! Thanks!

Edit - and to confirm, I did test specifying the template from package.json. That works as expected.

@gparlakov
Copy link
Owner Author

Do you want to test it with SCuri code? Well there is a way. SCuri code keeps dependencies in a shared folder (maintained by VS Code) so here's how to locate that folder on a machine and install scuri@next version

image

@JarvisJ FYI

@JarvisJ
Copy link

JarvisJ commented Jul 6, 2021

It works, using my template, with the vs-code extension. The extension still doesn't work in my multiroot workspace. I describe that issue here:

gparlakov/scuri-code#4 (comment)

@Z-Newman
Copy link

Hey there. I'm picking up where Mr. JarvisJ left off (literally, same company and product), I'm finding that it would be very helpful to be able to forEach through the declaration and buildExports like we can through the params and publicMethods, there are some places where we'd like to be able to consistently override the line-by-line generation for specific classes.

@gparlakov
Copy link
Owner Author

Hey, @Z-Newman,

I think you can do that with the params property that's already exposed to the template.

From index.ts

scuri/src/spec/index.ts

Lines 173 to 184 in 969dd91

applyTemplates({
// the name of the new spec file
specFileName,
normalizedName: normalizedName,
className: name,
publicMethods,
declaration: toDeclaration(),
builderExports: toBuilderExports(),
constructorParams: toConstructorParams(),
params,
shorthand
}),

The declarations and buildExports are just representations of the (constructor) params:

scuri/src/spec/index.ts

Lines 200 to 216 in 969dd91

function toDeclaration() {
return params
.map(p =>
p.type === 'string' || p.type === 'number'
? `let ${p.name}:${p.type};`
: `const ${p.name} = autoSpy(${p.type});`
)
.join(EOL);
}
function toBuilderExports() {
return params.length > 0
? params
.map(p => p.name)
.join(',' + EOL)
.concat(',')
: '';
}

Here's an example of the template using these params

https://gist.github.com/gparlakov/f299011829e229c9d37cf0cb38506d97#file-my-tmpl-L6-L9

@Z-Newman
Copy link

Z-Newman commented Oct 24, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants