Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create hatchet tests to be shared across languages #833

Merged
merged 7 commits into from
Aug 24, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.anvil
.DS_Store
repos/*
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Node.js Buildpack Changelog

## main
- Added Hatchet regression tests ([#833](https://github.com/heroku/heroku-buildpack-nodejs/pull/833))

## v175 (2020-08-13)
- Install Yarn version at 1.22.x when not specified in package.json engines ([#817](https://github.com/heroku/heroku-buildpack-nodejs/pull/817))
Expand Down
9 changes: 8 additions & 1 deletion hatchet.json
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
{}
{
"heroku": [
"heroku/node-js-getting-started"
],
"nodejs": [
"sharpstone/default-node"
]
}
5 changes: 5 additions & 0 deletions hatchet.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- - "./repos/heroku/node-js-getting-started"
- master
- - "./repos/nodejs/default-node"
- master
1 change: 1 addition & 0 deletions spec/fixtures/badNodeVersion/Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: node index.js
3 changes: 3 additions & 0 deletions spec/fixtures/badNodeVersion/app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "hello-world"
}
46 changes: 46 additions & 0 deletions spec/fixtures/badNodeVersion/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env node

const http = require('http');
const crypto = require('crypto');

const PORT = process.env.PORT || 5000;

// This will block the event loop for ~lengths of time
function blockCpuFor(ms) {
var now = new Date().getTime();
var result = 0
while(true) {
result += Math.random() * Math.random();
if (new Date().getTime() > now +ms)
return;
}
}

// block the event loop for 100ms every second
setInterval(() => {
blockCpuFor(100);
}, 1000)

// block the event loop for 1sec every 30 seconds
setInterval(() => {
blockCpuFor(1000);
}, 30000)

// Allocate and erase memory on an interval
let store = [];

setInterval(() => {
store.push(crypto.randomBytes(1000000).toString('hex'));
}, 500);

setInterval(() => {
store = [];
}, 60000);

const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end("Hello, world!");
})

server.listen(PORT, () => console.log(`Listening on ${PORT}`));
21 changes: 21 additions & 0 deletions spec/fixtures/badNodeVersion/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "hello-world",
"version": "1.0.0",
"engines": {
"node": "14.x.badversion"
},
"scripts": {
"prettify": "prettier --single-quote --trailing-comma all --write 'bin/*' 'src/**/*.js'",
"test": "jest --silent",
"dev": "nodemon --watch . --watch src/* src/index.js",
"build": "echo NODE_OPTIONS: $NODE_OPTIONS"
},
"main": "index.js",
"license": "MIT",
"devDependencies": {
"jest": "^19.0.2",
"nodemon": "^1.19.4",
"prettier": "^0.22.0"
},
"dependencies": {}
}
14 changes: 14 additions & 0 deletions spec/hatchet/absolute_path_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require_relative '../spec_helper'

#Test that all paths set by the buildpack are absolute instead of relative
describe "Buildpack paths" do
it "are absolute" do
buildpacks = [
ENV["HATCHET_BUILDPACK_BASE"],
lillianzhang331 marked this conversation as resolved.
Show resolved Hide resolved
"https://github.com/sharpstone/force_absolute_paths_buildpack"
]
Hatchet::Runner.new("node-js-getting-started", buildpacks: buildpacks).deploy do |app|
#deploy works
end
end
end
15 changes: 15 additions & 0 deletions spec/hatchet/ci_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require_relative '../spec_helper'

#Test CI deploys run tests and use the cache
describe "Heroku CI" do
it "Uses the cache" do
Hatchet::Runner.new("node-js-getting-started").run_ci do |test_run|
# puts test_run.output
lillianzhang331 marked this conversation as resolved.
Show resolved Hide resolved
# what is the behavior of this for node js
# expect(test_run.output).to match("Fetching rake")
expect(test_run.output).to_not include("Restoring cache")
test_run.run_again
expect(test_run.output).to include("Restoring cache")
end
end
end
10 changes: 10 additions & 0 deletions spec/hatchet/getting_started_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require_relative '../spec_helper'

#Test deploying the getting started guide works
describe "Heroku node getting started" do
it "clears runtime cache" do
Hatchet::Runner.new("node-js-getting-started").deploy do |app|
#Deploy works
end
end
end
26 changes: 26 additions & 0 deletions spec/hatchet/stack_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require_relative "../spec_helper"

describe "Stack Changes" do
#Test upgrading stack invalidates the cache
it "should not restore cached directories" do
app = Hatchet::Runner.new("default-node", allow_failure: true, stack: "heroku-18").setup!
app.deploy do |app, heroku|
app.update_stack("heroku-16")
run!('git commit --allow-empty -m "heroku-16 migrate"')
app.push!
expect(app.output).to include("Cached directories were not restored due to a change in version of node, npm, yarn or stack")
end
end

#Test cache for regular deploys is used on repeated deploys
it "should not restore cache if the stack did not change" do
app = Hatchet::Runner.new('default-node', stack: "heroku-16").setup!
app.deploy do |app, heroku|
app.update_stack("heroku-16")
run!('git commit --allow-empty -m "cedar migrate"')
app.push!
expect(app.output).to_not include("Cached directories were not restored due to a change in version of node, npm, yarn or stack")
expect(app.output).to include("not cached - skipping")
end
end
end
19 changes: 19 additions & 0 deletions spec/hatchet/version_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require_relative '../spec_helper'

#Test that builds fail when a bad version is specified
describe "bad node version" do
it "gives a helpful error" do
Hatchet::Runner.new("spec/fixtures/repos/default-node", allow_failure: true).tap do |app|
app.before_deploy do
File.open("package.json", "w+") do |f|
f.write '{"engines": {
"node": "14.x.badversion"
}}'
end
end
app.deploy do
expect(app.output).to include("Invalid semantic version \"14.x.badversion\"")
end
end
end
end
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
ENV['HATCHET_BUILDPACK_BASE'] = 'https://github.com/heroku/heroku-buildpack-nodejs.git'

require 'rspec/core'
require 'hatchet'
require 'fileutils'
Expand Down