diff --git a/.circleci/config.yml b/.circleci/config.yml index aa672c2962..d1ec5977d8 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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: diff --git a/npm_and_yarn/helpers/package.json b/npm_and_yarn/helpers/package.json index 500e8cfdb5..d84bfd1d46 100644 --- a/npm_and_yarn/helpers/package.json +++ b/npm_and_yarn/helpers/package.json @@ -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" } } diff --git a/npm_and_yarn/helpers/test/npm/updater.test.js b/npm_and_yarn/helpers/test/npm/updater.test.js index 2093ccde0f..b05ab35014 100644 --- a/npm_and_yarn/helpers/test/npm/updater.test.js +++ b/npm_and_yarn/helpers/test/npm/updater.test.js @@ -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, @@ -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", [ { diff --git a/npm_and_yarn/helpers/test/yarn/updater.test.js b/npm_and_yarn/helpers/test/yarn/updater.test.js index 8eccc01bfa..903322447f 100644 --- a/npm_and_yarn/helpers/test/yarn/updater.test.js +++ b/npm_and_yarn/helpers/test/yarn/updater.test.js @@ -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, [ { @@ -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, [ { @@ -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, [ { @@ -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 { diff --git a/npm_and_yarn/helpers/yarn.lock b/npm_and_yarn/helpers/yarn.lock index 734f32b64c..d25f58e990 100644 --- a/npm_and_yarn/helpers/yarn.lock +++ b/npm_and_yarn/helpers/yarn.lock @@ -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"