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

Solution to vite pulling in routes/**/*.spec.ts #35

Closed
jtlapp opened this issue Mar 22, 2022 · 2 comments · Fixed by #39
Closed

Solution to vite pulling in routes/**/*.spec.ts #35

jtlapp opened this issue Mar 22, 2022 · 2 comments · Fixed by #39
Assignees
Labels
bug Something isn't working

Comments

@jtlapp
Copy link

jtlapp commented Mar 22, 2022

I needed to add this package to an existing repo, violating the precondition requirement that "You must start with a fresh copy of the official SvelteKit template." I don't know if this caused my problem, but the demo routes/index.spec.ts bombed vite:

Screen Shot 2022-03-22 at 14 24 14

I solved the problem by modifying svelte.config.js based on this SO answer. This is my new config file:

import adapter from '@sveltejs/adapter-auto';
import preprocess from 'svelte-preprocess';

/** @type {import('@sveltejs/kit').Config} */
const config = {
    // Consult https://github.com/sveltejs/svelte-preprocess
    // for more information about preprocessors
    preprocess: preprocess(),

    kit: {
        adapter: adapter(),
        routes: filepath => {
            return ![
                // exclude *test.js files
                /\.spec\.ts$/,

                // original default config
                /(?:(?:^_|\/_)|(?:^\.|\/\.)(?!well-known))/,
            ].some(regex => regex.test(filepath))
        },
    }
};

export default config;

I don't know if my violating the precondition requirement caused the problem, but I had an existing repo, and I needed the package.

@rossyman
Copy link
Owner

I'm happy enough with this as a solution to Vite picking up .spec files as a route. I'll raise a PR to include this extra reg-ex exclusion

@rossyman rossyman self-assigned this May 12, 2022
@rossyman rossyman added the bug Something isn't working label May 12, 2022
@rossyman
Copy link
Owner

After further inspection, I've found that the library we're using to apply the preset, doesn't allow the modification of JS files. Therefore, I'm going to update the documentation around this issue, and raise a PR to close this one off. Cheers for the help 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants