From 20ffc92de2fee4f4ce40ceb891b158a11f0b972f Mon Sep 17 00:00:00 2001 From: chee Date: Mon, 18 Feb 2019 06:30:17 +0000 Subject: [PATCH] Add tests for parse-lockfile --- tests/functions/parse-lockfile.js | 40 +++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 tests/functions/parse-lockfile.js diff --git a/tests/functions/parse-lockfile.js b/tests/functions/parse-lockfile.js new file mode 100644 index 0000000..8e2a294 --- /dev/null +++ b/tests/functions/parse-lockfile.js @@ -0,0 +1,40 @@ +import expect from "expect" +import sinon from "sinon" +import parseLockfile from "../../functions/parse-lockfile" + +describe("functions/parse-lockfile", () => { + afterEach(() => sinon.restore()) + it("dislikes non-json", async () => { + let exit = sinon.stub(process, "exit") + expect(exit.called).toBe(false) + await parseLockfile("{") + expect(exit.called).toBe(true) + }) + + it("dislikes non-lockfile json", async () => { + let exit = sinon.stub(process, "exit") + expect(exit.called).toBe(false) + await parseLockfile("{a: []}") + expect(exit.called).toBe(true) + }) + + it("likes a lockfile", async () => { + let exit = sinon.stub(process, "exit") + expect(exit.called).toBe(false) + let lockfile = await parseLockfile(` + { + "name": "lil-yeet", + "lockfileVersion": 1, + "requires": true, + "dependencies": {} + } + `) + expect(exit.called).toBe(false) + expect(lockfile).toEqual({ + name: "lil-yeet", + lockfileVersion: 1, + requires: true, + dependencies: {} + }) + }) +})