Skip to content

Commit

Permalink
Fix js helper tests
Browse files Browse the repository at this point in the history
  • Loading branch information
feelepxyz committed Sep 16, 2019
1 parent 698064a commit 07377aa
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 21 deletions.
2 changes: 2 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ jobs:
- run: cd npm_and_yarn/helpers && yarn lint

# Run tests
- run: cd npm_and_yarn/helpers && yarn test

- store_test_results:
path: ~/rspec
- store_artifacts:
Expand Down
3 changes: 2 additions & 1 deletion npm_and_yarn/helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"eslint-plugin-prettier": "^3.1.0",
"jest": "^24.9.0",
"nock": "^11.3.3",
"prettier": "^1.18.2"
"prettier": "^1.18.2",
"rimraf": "^3.0.0"
}
}
20 changes: 14 additions & 6 deletions npm_and_yarn/helpers/test/npm/updater.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const path = require("path");
const os = require("os");
const fs = require("fs");
const rimraf = require("rimraf");
const nock = require("nock");
const {
updateDependencyFiles,
Expand All @@ -12,29 +13,36 @@ describe("updater", () => {
let tempDir;
beforeEach(() => {
nock("https://registry.npmjs.org")
.persist()
.get("/left-pad")
.reply(200, helpers.loadFixture("npm-left-pad.json"));
.replyWithFile(
200,
path.join(__dirname, "fixtures", "npm-left-pad.json"),
{
"Content-Type": "application/json"
}
);

tempDir = fs.mkdtempSync(os.tmpdir() + path.sep);
});
afterEach(() => fs.rmdirSync(tempDir));
afterEach(() => rimraf.sync(tempDir));

async function copyDependencies(sourceDir, destDir) {
function copyDependencies(sourceDir, destDir) {
const srcPackageJson = path.join(
__dirname,
`fixtures/updater/${sourceDir}/package.json`
);
await fs.copyFile(srcPackageJson, `${destDir}/package.json`);
fs.copyFileSync(srcPackageJson, `${destDir}/package.json`);

const srcLockfile = path.join(
__dirname,
`fixtures/updater/${sourceDir}/package-lock.json`
);
await fs.copyFile(srcLockfile, `${destDir}/package-lock.json`);
fs.copyFileSync(srcLockfile, `${destDir}/package-lock.json`);
}

it("generates an updated package-lock.json", async () => {
await copyDependencies("original", tempDir);
copyDependencies("original", tempDir);

const result = await updateDependencyFiles(tempDir, "package-lock.json", [
{
Expand Down
40 changes: 26 additions & 14 deletions npm_and_yarn/helpers/test/yarn/updater.test.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,55 @@
const path = require("path");
const os = require("os");
const fs = require("fs");
const rimraf = require("rimraf");
const nock = require("nock");
const {
updateDependencyFiles,
updateVersionPattern
} = require("../../lib/yarn/updater");
const { updateDependencyFiles } = require("../../lib/yarn/updater");
const helpers = require("./helpers");

describe("updater", () => {
let tempDir;
beforeEach(() => {
nock("https://registry.yarnpkg.com")
.persist()
.get("/left-pad")
.reply(200, helpers.loadFixture("yarnpkg-left-pad.json"));
.replyWithFile(
200,
path.join(__dirname, "fixtures", "yarnpkg-left-pad.json"),
{
"Content-Type": "application/json"
}
);
nock("https://registry.yarnpkg.com")
.persist()
.get("/is-positive")
.reply(200, helpers.loadFixture("yarnpkg-is-positive.json"));
.replyWithFile(
200,
path.join(__dirname, "fixtures", "yarnpkg-is-positive.json"),
{
"Content-Type": "application/json"
}
);

tempDir = fs.mkdtempSync(os.tmpdir() + path.sep);
});
afterEach(() => fs.rmdirSync(tempDir));
afterEach(() => rimraf.sync(tempDir));

async function copyDependencies(sourceDir, destDir) {
function copyDependencies(sourceDir, destDir) {
const srcPackageJson = path.join(
__dirname,
`fixtures/updater/${sourceDir}/package.json`
);
await fs.copyFile(srcPackageJson, `${destDir}/package.json`);
fs.copyFileSync(srcPackageJson, `${destDir}/package.json`);

const srcYarnLock = path.join(
__dirname,
`fixtures/updater/${sourceDir}/yarn.lock`
);
await fs.copyFile(srcYarnLock, `${destDir}/yarn.lock`);
fs.copyFileSync(srcYarnLock, `${destDir}/yarn.lock`);
}

it("generates an updated yarn.lock", async () => {
await copyDependencies("original", tempDir);
copyDependencies("original", tempDir);

const result = await updateDependencyFiles(tempDir, [
{
Expand All @@ -52,7 +64,7 @@ describe("updater", () => {
});

it("doesn't modify existing version comments", async () => {
await copyDependencies("with-version-comments", tempDir);
copyDependencies("with-version-comments", tempDir);

const result = await updateDependencyFiles(tempDir, [
{
Expand All @@ -66,7 +78,7 @@ describe("updater", () => {
});

it("doesn't add version comments if they're not already there", async () => {
await copyDependencies("original", tempDir);
copyDependencies("original", tempDir);

const result = await updateDependencyFiles(tempDir, [
{
Expand All @@ -80,7 +92,7 @@ describe("updater", () => {
});

it("doesn't show an interactive prompt when resolution fails", async () => {
await copyDependencies("original", tempDir);
copyDependencies("original", tempDir);

expect.assertions(1);
try {
Expand Down
7 changes: 7 additions & 0 deletions npm_and_yarn/helpers/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5347,6 +5347,13 @@ rimraf@2.6.3:
dependencies:
glob "^7.1.3"

rimraf@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-3.0.0.tgz#614176d4b3010b75e5c390eb0ee96f6dc0cebb9b"
integrity sha512-NDGVxTsjqfunkds7CqsOiEnxln4Bo7Nddl3XhS4pXg5OzwkLqJ971ZVAAnB+DDLnF76N+VnDEiBHaVV8I06SUg==
dependencies:
glob "^7.1.3"

rsvp@^4.8.4:
version "4.8.5"
resolved "https://registry.yarnpkg.com/rsvp/-/rsvp-4.8.5.tgz#c8f155311d167f68f21e168df71ec5b083113734"
Expand Down

0 comments on commit 07377aa

Please sign in to comment.