require node 10, rewrite tests to jest

This commit is contained in:
silverwind 2020-03-08 10:23:44 +01:00
parent 5d39d8b6dc
commit fc28e011ee
Signed by: silverwind
GPG Key ID: 2E62B41C93869443
13 changed files with 1818 additions and 307 deletions

@ -1,9 +1,7 @@
language: node_js
node_js:
- 8
- 10
- 12
os:
- linux
- osx
- windows

@ -1,6 +1,6 @@
test:
npx eslint --color --quiet *.js
node --trace-deprecation --throw-deprecation test.js
yarn -s run eslint --color .
yarn -s run jest --color
publish:
git push -u --tags origin master
@ -8,25 +8,22 @@ publish:
deps:
rm -rf node_modules
npm i
yarn
update:
node updates.js -cu
yarn -s run updates -cu
$(MAKE) deps
patch:
$(MAKE) test
npx versions -C patch
patch: test
yarn -s run versions -C patch
$(MAKE) publish
minor:
$(MAKE) test
npx versions -C minor
minor: test
yarn -s run versions -C minor
$(MAKE) publish
major:
$(MAKE) test
npx versions -C major
major: test
yarn -s run versions -C major
$(MAKE) publish
.PHONY: test publish deps update patch minor major

1545
fixtures/1500-deps.json Normal file

File diff suppressed because it is too large Load Diff

@ -5,13 +5,12 @@
"author": "silverwind",
"repository": "silverwind/updates",
"license": "BSD-2-Clause",
"main": "updates.js",
"bin": "./updates.js",
"engines": {
"node": ">=8"
"node": ">=10"
},
"scripts": {
"test": "npx eslint --color --quiet *.js && node --trace-deprecation --throw-deprecation test.js"
"test": "make test"
},
"keywords": [
"dependencies",
@ -30,6 +29,7 @@
"chalk": "3.0.0",
"find-up": "4.1.0",
"hosted-git-info": "3.0.2",
"jest": "25.1.0",
"make-fetch-happen": "6.1.0",
"minimist": "1.2.0",
"rc": "1.2.8",
@ -46,5 +46,8 @@
"execa": "3.4.0",
"tempy": "0.3.0",
"versions": "7.0.4"
},
"jest": {
"verbose": false
}
}

546
test.js

@ -1,319 +1,287 @@
"use strict";
const assert = require("assert");
const process = require("process");
const execa = require("execa");
const createTestServer = require("create-test-server");
const tempy = require("tempy");
const fs = require("fs");
const path = require("path");
const del = require("del");
const execa = require("execa");
const tempy = require("tempy");
const {join} = require("path");
const {test, expect, beforeAll, afterAll} = global;
const {writeFile, readFile} = require("fs").promises;
const testDir = tempy.directory();
let server;
async function clean() {
await del(testDir, {force: true});
if (server) {
await server.close();
}
}
const testPackages = [
"gulp-sourcemaps",
"prismjs",
"svgstore",
"html-webpack-plugin",
"noty",
"jpeg-buffer-orientation",
"styled-components",
"@babel/preset-env",
];
async function setup() {
beforeAll(async () => {
server = await createTestServer();
// Server response
for (const packageName of [
"gulp-sourcemaps",
"prismjs",
"svgstore",
"html-webpack-plugin",
"noty",
"jpeg-buffer-orientation",
"styled-components",
"@babel/preset-env",
]) {
for (const packageName of testPackages) {
const name = packageName.replace(/\//g, "%2f");
const text = fs.readFileSync(path.join(__dirname, "info", `${name}.json`), "utf8");
server.get(
`/${name}`,
text
);
const path = join(__dirname, "fixtures", "registry-responses", `${name}.json`);
const text = await readFile(path, "utf8");
server.get(`/${name}`, text);
}
const {sslUrl: registry} = server;
// Fake registry
fs.writeFileSync(path.join(testDir, ".npmrc"), `registry=${registry}`);
await writeFile(join(testDir, ".npmrc"), `registry=${registry}`);
// Copy fixture
fs.writeFileSync(
path.join(testDir, "test.json"),
fs.readFileSync("test.json")
);
await writeFile(join(testDir, "test.json"), await readFile("test.json", "utf8"));
});
afterAll(async () => {
await del(testDir, {force: true});
if (server) await server.close();
});
function makeTest(args, expected) {
return async () => {
const {stdout} = await execa(
join(__dirname, "./updates.js"),
args.split(/\s+/),
{cwd: testDir},
);
return expect(JSON.parse(stdout)).toEqual({results: expected});
};
}
async function exit(err) {
await clean();
if (err) {
console.info(err);
test("latest", makeTest("-j -f test.json", {
dependencies: {
"gulp-sourcemaps": {
old: "2.0.0",
new: "2.6.5",
info: "https://github.com/gulp-sourcemaps/gulp-sourcemaps",
},
"prismjs": {
old: "1.0.0",
new: "1.17.1",
info: "https://github.com/LeaVerou/prism",
},
"svgstore": {
old: "^3.0.0",
new: "^3.0.0-2",
info: "https://github.com/svgstore/svgstore",
},
"html-webpack-plugin": {
old: "4.0.0-alpha.2",
new: "4.0.0-beta.11",
info: "https://github.com/jantimon/html-webpack-plugin",
},
"noty": {
old: "3.1.0",
new: "3.2.0-beta",
info: "https://github.com/needim/noty",
},
"jpeg-buffer-orientation": {
old: "0.0.0",
new: "2.0.3",
info: "https://github.com/fisker/jpeg-buffer-orientation",
},
"styled-components": {
old: "2.5.0-1",
new: "5.0.0-rc.2",
info: "https://github.com/styled-components/styled-components",
},
"@babel/preset-env": {
old: "7.0.0",
new: "7.7.6",
info: "https://github.com/babel/babel/tree/master/packages/babel-preset-env",
}
},
peerDependencies: {
"@babel/preset-env": {
"old": "~6.0.0",
"new": "~7.7.6",
"info": "https://github.com/babel/babel/tree/master/packages/babel-preset-env"
}
},
}));
test("greatest", makeTest("-j -g -f test.json", {
dependencies: {
"gulp-sourcemaps": {
old: "2.0.0",
new: "2.6.5",
info: "https://github.com/gulp-sourcemaps/gulp-sourcemaps",
},
"prismjs": {
old: "1.0.0",
new: "1.17.1",
info: "https://github.com/LeaVerou/prism",
},
"html-webpack-plugin": {
old: "4.0.0-alpha.2",
new: "4.0.0-beta.11",
info: "https://github.com/jantimon/html-webpack-plugin",
},
"noty": {
old: "3.1.0",
new: "3.1.4",
info: "https://github.com/needim/noty",
},
"jpeg-buffer-orientation": {
old: "0.0.0",
new: "2.0.3",
info: "https://github.com/fisker/jpeg-buffer-orientation",
},
"styled-components": {
old: "2.5.0-1",
new: "5.0.0-rc.2",
info: "https://github.com/styled-components/styled-components",
},
"@babel/preset-env": {
old: "7.0.0",
new: "7.7.6",
info: "https://github.com/babel/babel/tree/master/packages/babel-preset-env",
}
},
peerDependencies: {
"@babel/preset-env": {
"old": "~6.0.0",
"new": "~7.7.6",
"info": "https://github.com/babel/babel/tree/master/packages/babel-preset-env"
}
}
process.exit(err ? 1 : 0);
}
}));
async function run(args) {
const {stdout} = await execa(
path.join(process.cwd(), "./updates.js"),
args.split(/\s+/),
{
cwd: testDir
test("prerelease", makeTest("-j -g -p -f test.json", {
dependencies: {
"gulp-sourcemaps": {
old: "2.0.0",
new: "2.6.5",
info: "https://github.com/gulp-sourcemaps/gulp-sourcemaps",
},
"prismjs": {
old: "1.0.0",
new: "1.17.1",
info: "https://github.com/LeaVerou/prism",
},
"svgstore": {
old: "^3.0.0",
new: "^3.0.0-2",
info: "https://github.com/svgstore/svgstore",
},
"html-webpack-plugin": {
old: "4.0.0-alpha.2",
new: "4.0.0-beta.11",
info: "https://github.com/jantimon/html-webpack-plugin",
},
"noty": {
old: "3.1.0",
new: "3.2.0-beta",
info: "https://github.com/needim/noty",
},
"jpeg-buffer-orientation": {
old: "0.0.0",
new: "2.0.3",
info: "https://github.com/fisker/jpeg-buffer-orientation",
},
"styled-components": {
old: "2.5.0-1",
new: "5.0.0-rc.2",
info: "https://github.com/styled-components/styled-components",
},
"@babel/preset-env": {
old: "7.0.0",
new: "7.7.6",
info: "https://github.com/babel/babel/tree/master/packages/babel-preset-env",
}
);
return JSON.parse(stdout);
}
async function main() {
await setup();
assert.deepStrictEqual(await run("-j -f test.json"), {
results: {
dependencies: {
"gulp-sourcemaps": {
old: "2.0.0",
new: "2.6.5",
info: "https://github.com/gulp-sourcemaps/gulp-sourcemaps",
},
"prismjs": {
old: "1.0.0",
new: "1.17.1",
info: "https://github.com/LeaVerou/prism",
},
"svgstore": {
old: "^3.0.0",
new: "^3.0.0-2",
info: "https://github.com/svgstore/svgstore",
},
"html-webpack-plugin": {
old: "4.0.0-alpha.2",
new: "4.0.0-beta.11",
info: "https://github.com/jantimon/html-webpack-plugin",
},
"noty": {
old: "3.1.0",
new: "3.2.0-beta",
info: "https://github.com/needim/noty",
},
"jpeg-buffer-orientation": {
old: "0.0.0",
new: "2.0.3",
info: "https://github.com/fisker/jpeg-buffer-orientation",
},
"styled-components": {
old: "2.5.0-1",
new: "5.0.0-rc.2",
info: "https://github.com/styled-components/styled-components",
},
"@babel/preset-env": {
old: "7.0.0",
new: "7.7.6",
info: "https://github.com/babel/babel/tree/master/packages/babel-preset-env",
}
},
peerDependencies: {
"@babel/preset-env": {
"old": "~6.0.0",
"new": "~7.7.6",
"info": "https://github.com/babel/babel/tree/master/packages/babel-preset-env"
}
},
},
peerDependencies: {
"@babel/preset-env": {
"old": "~6.0.0",
"new": "~7.7.6",
"info": "https://github.com/babel/babel/tree/master/packages/babel-preset-env"
}
});
},
}));
assert.deepStrictEqual(await run("-j -g -f test.json"), {
results: {
dependencies: {
"gulp-sourcemaps": {
old: "2.0.0",
new: "2.6.5",
info: "https://github.com/gulp-sourcemaps/gulp-sourcemaps",
},
"prismjs": {
old: "1.0.0",
new: "1.17.1",
info: "https://github.com/LeaVerou/prism",
},
"html-webpack-plugin": {
old: "4.0.0-alpha.2",
new: "4.0.0-beta.11",
info: "https://github.com/jantimon/html-webpack-plugin",
},
"noty": {
old: "3.1.0",
new: "3.1.4",
info: "https://github.com/needim/noty",
},
"jpeg-buffer-orientation": {
old: "0.0.0",
new: "2.0.3",
info: "https://github.com/fisker/jpeg-buffer-orientation",
},
"styled-components": {
old: "2.5.0-1",
new: "5.0.0-rc.2",
info: "https://github.com/styled-components/styled-components",
},
"@babel/preset-env": {
old: "7.0.0",
new: "7.7.6",
info: "https://github.com/babel/babel/tree/master/packages/babel-preset-env",
}
},
peerDependencies: {
"@babel/preset-env": {
"old": "~6.0.0",
"new": "~7.7.6",
"info": "https://github.com/babel/babel/tree/master/packages/babel-preset-env"
}
}
test("release", makeTest("-j -R -f test.json", {
dependencies: {
"gulp-sourcemaps": {
old: "2.0.0",
new: "2.6.5",
info: "https://github.com/gulp-sourcemaps/gulp-sourcemaps",
},
"prismjs": {
old: "1.0.0",
new: "1.17.1",
info: "https://github.com/LeaVerou/prism",
},
"svgstore": {
old: "^3.0.0",
new: "^2.0.3",
info: "https://github.com/svgstore/svgstore",
},
"html-webpack-plugin": {
old: "4.0.0-alpha.2",
new: "3.2.0",
info: "https://github.com/jantimon/html-webpack-plugin",
},
"noty": {
old: "3.1.0",
new: "3.1.4",
info: "https://github.com/needim/noty",
},
"jpeg-buffer-orientation": {
old: "0.0.0",
new: "2.0.3",
info: "https://github.com/fisker/jpeg-buffer-orientation",
},
"styled-components": {
old: "2.5.0-1",
new: "4.4.1",
info: "https://github.com/styled-components/styled-components",
},
"@babel/preset-env": {
old: "7.0.0",
new: "7.7.6",
info: "https://github.com/babel/babel/tree/master/packages/babel-preset-env",
}
});
assert.deepStrictEqual(await run("-j -g -p -f test.json"), {
results: {
dependencies: {
"gulp-sourcemaps": {
old: "2.0.0",
new: "2.6.5",
info: "https://github.com/gulp-sourcemaps/gulp-sourcemaps",
},
"prismjs": {
old: "1.0.0",
new: "1.17.1",
info: "https://github.com/LeaVerou/prism",
},
"svgstore": {
old: "^3.0.0",
new: "^3.0.0-2",
info: "https://github.com/svgstore/svgstore",
},
"html-webpack-plugin": {
old: "4.0.0-alpha.2",
new: "4.0.0-beta.11",
info: "https://github.com/jantimon/html-webpack-plugin",
},
"noty": {
old: "3.1.0",
new: "3.2.0-beta",
info: "https://github.com/needim/noty",
},
"jpeg-buffer-orientation": {
old: "0.0.0",
new: "2.0.3",
info: "https://github.com/fisker/jpeg-buffer-orientation",
},
"styled-components": {
old: "2.5.0-1",
new: "5.0.0-rc.2",
info: "https://github.com/styled-components/styled-components",
},
"@babel/preset-env": {
old: "7.0.0",
new: "7.7.6",
info: "https://github.com/babel/babel/tree/master/packages/babel-preset-env",
}
},
peerDependencies: {
"@babel/preset-env": {
"old": "~6.0.0",
"new": "~7.7.6",
"info": "https://github.com/babel/babel/tree/master/packages/babel-preset-env"
}
},
},
peerDependencies: {
"@babel/preset-env": {
"old": "~6.0.0",
"new": "~7.7.6",
"info": "https://github.com/babel/babel/tree/master/packages/babel-preset-env"
}
});
},
}));
assert.deepStrictEqual(await run("-j -R -f test.json"), {
results: {
dependencies: {
"gulp-sourcemaps": {
old: "2.0.0",
new: "2.6.5",
info: "https://github.com/gulp-sourcemaps/gulp-sourcemaps",
},
"prismjs": {
old: "1.0.0",
new: "1.17.1",
info: "https://github.com/LeaVerou/prism",
},
"svgstore": {
old: "^3.0.0",
new: "^2.0.3",
info: "https://github.com/svgstore/svgstore",
},
"html-webpack-plugin": {
old: "4.0.0-alpha.2",
new: "3.2.0",
info: "https://github.com/jantimon/html-webpack-plugin",
},
"noty": {
old: "3.1.0",
new: "3.1.4",
info: "https://github.com/needim/noty",
},
"jpeg-buffer-orientation": {
old: "0.0.0",
new: "2.0.3",
info: "https://github.com/fisker/jpeg-buffer-orientation",
},
"styled-components": {
old: "2.5.0-1",
new: "4.4.1",
info: "https://github.com/styled-components/styled-components",
},
"@babel/preset-env": {
old: "7.0.0",
new: "7.7.6",
info: "https://github.com/babel/babel/tree/master/packages/babel-preset-env",
}
},
peerDependencies: {
"@babel/preset-env": {
"old": "~6.0.0",
"new": "~7.7.6",
"info": "https://github.com/babel/babel/tree/master/packages/babel-preset-env"
}
},
}
});
assert.deepStrictEqual(await run("-j -P -f test.json"), {
results: {
dependencies: {
"gulp-sourcemaps": {
old: "2.0.0",
new: "2.0.1",
info: "https://github.com/floridoo/gulp-sourcemaps",
},
"svgstore": {
old: "^3.0.0",
new: "^3.0.0-2",
info: "https://github.com/svgstore/svgstore",
},
"html-webpack-plugin": {
old: "4.0.0-alpha.2",
new: "4.0.0-beta.11",
info: "https://github.com/jantimon/html-webpack-plugin",
},
"noty": {
old: "3.1.0",
new: "3.1.4",
info: "https://github.com/needim/noty",
},
},
}
});
}
main().then(exit).catch(exit);
test("patch", makeTest("-j -P -f test.json", {
dependencies: {
"gulp-sourcemaps": {
old: "2.0.0",
new: "2.0.1",
info: "https://github.com/floridoo/gulp-sourcemaps",
},
"svgstore": {
old: "^3.0.0",
new: "^3.0.0-2",
info: "https://github.com/svgstore/svgstore",
},
"html-webpack-plugin": {
old: "4.0.0-alpha.2",
new: "4.0.0-beta.11",
info: "https://github.com/jantimon/html-webpack-plugin",
},
"noty": {
old: "3.1.0",
new: "3.1.4",
info: "https://github.com/needim/noty",
},
},
}));