bahmutov / snap-shot

Jest-like snapshot feature for the rest of us, works magically by finding the right caller function
169 stars 3 forks source link

Doesn't support test names with apostrophes #48

Closed tivac closed 7 years ago

tivac commented 7 years ago
it("should support apostrophe'd test names", () => {
    snapshot(42);
});

will succeed on the first run, but create a snapshot file like this.

exports['should support apostrophe'd test names 1'] = 42

(note the single-quote within single-quotes that makes the snapshot invalid javascript).

Then any later attempts to run the tests cause a massive :fire:

exports['should support apostrophe'd test names 1'] = 42

evalmachine.<anonymous>:1
exports['should support apostrophe'd test names 1'] = 42
                                   ^
SyntaxError: Unexpected identifier
    at createScript (vm.js:53:10)
    at Object.runInNewContext (vm.js:91:10)
    at loadSnaps (C:\Users\pcavit\Desktop\snap-shot\node_modules\snap-shot-core\src\file-system.js:26:8)
    at Object.loadSnapshots (C:\Users\pcavit\Desktop\snap-shot\node_modules\snap-shot-core\src\file-system.js:5
4:17)
    at storeValue (C:\Users\pcavit\Desktop\snap-shot\node_modules\snap-shot-core\src\index.js:59:24)
    at setOrCheckValue (C:\Users\pcavit\Desktop\snap-shot\node_modules\snap-shot-core\src\index.js:114:7)
    at snapShotCore (C:\Users\pcavit\Desktop\snap-shot\node_modules\snap-shot-core\src\index.js:138:12)
    at setOrCheckValue (C:\Users\pcavit\Desktop\snap-shot\node_modules\snap-shot\src\index.js:137:5)
    at snapshot (C:\Users\pcavit\Desktop\snap-shot\node_modules\snap-shot\src\index.js:151:12)
    at Context.it (C:\Users\pcavit\Desktop\snap-shot\test\snap-shot.test.js:6:5)
    at callFn (C:\Users\pcavit\Desktop\snap-shot\node_modules\mocha\lib\runnable.js:345:21)
    at Test.Runnable.run (C:\Users\pcavit\Desktop\snap-shot\node_modules\mocha\lib\runnable.js:337:7)
    at Runner.runTest (C:\Users\pcavit\Desktop\snap-shot\node_modules\mocha\lib\runner.js:444:10)
    at C:\Users\pcavit\Desktop\snap-shot\node_modules\mocha\lib\runner.js:550:12
    at next (C:\Users\pcavit\Desktop\snap-shot\node_modules\mocha\lib\runner.js:361:14)
    at C:\Users\pcavit\Desktop\snap-shot\node_modules\mocha\lib\runner.js:371:7
    at next (C:\Users\pcavit\Desktop\snap-shot\node_modules\mocha\lib\runner.js:295:14)
    at Immediate.<anonymous> (C:\Users\pcavit\Desktop\snap-shot\node_modules\mocha\lib\runner.js:339:5)
    at runCallback (timers.js:666:20)
    at tryOnImmediate (timers.js:639:5)
    at processImmediate [as _immediateCallback] (timers.js:611:5)
  √ should support apostrophe'd test names

  1 passing (22ms)

which for some reason is still considered a passing test?

bahmutov commented 7 years ago

If you find another issue, I will make you a maintainer and let you deal with it ;)

tivac commented 7 years ago

I'm not trying to be trouble, honest 😅

bahmutov commented 7 years ago

I know, you are helping me and everyone else, I am just kidding!