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

Caching problem in tests (same generator and/or same prompts are used in different tests) #44

Closed
platinumazure opened this issue Sep 17, 2016 · 1 comment

Comments

@platinumazure
Copy link
Member

platinumazure commented Sep 17, 2016

Extracted from #42. That issue talks about us not escaping double quotes correctly when putting user input in JS code; this one talks about single quotes being replaced by double quotes somewhere in the generator internals.

Of course it's a caching problem.

@platinumazure platinumazure changed the title Single-quotes in user input are replaced with double-quotes Caching problem in tests (same generator and/or same prompts are used in different tests) Sep 17, 2016
platinumazure added a commit that referenced this issue Oct 17, 2016
Adding single quote pathological tests as well
@platinumazure
Copy link
Member Author

platinumazure commented Oct 18, 2016

Background: This is a follow-up issue to #42 (originally solved by #45), where I wanted to make sure that if a user enters certain characters (mostly quotes), that we wouldn't generate a file that was syntactically invalid. I wanted to do so without using XML escapes, which are not what the user would expect.

Solving the original issue

For example: if a user enters var x = "foo"; for an example of invalid code and we just put that into the output template without checking, we would get something like this:

// ...
ruleTester.run({
    // ...
    invalid: [
        {
            code: "var x = "foo";",
            errors: "Fill me in"
        }
    ]
}

Before #45, we were using <%= %> delimiters around string injections in the templates, which by default do XML-escaping. So as a result, the code looked like this: "var x = &#38;foo&#38;;" Which got around the syntax issue but required the user to clean up afterwards. So I fixed that to just do a simple regex substitution.

The problem I'm now trying to solve

When I submitted #45, I wanted to add tests for double and single quotes, so we know that the code is behaving correctly. However, I ran into the trouble of require() caching files by module path, though I didn't recognize it at the time. So I ended up stripping out half my tests (they were commented out originally, but I was asked to remove them) in order to have some coverage around the double quote case, which is the one I knew was problematic.

Now that I'm using require-uncached, I can add all my single-quote tests back in. So this isn't really solving a new problem, just adding test coverage that I couldn't add originally due to require()'s caching nature.

platinumazure added a commit that referenced this issue Oct 19, 2016
Adding single quote pathological tests as well
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants