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 all 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
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 = [
:default,
"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
12 changes: 12 additions & 0 deletions spec/hatchet/ci_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
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|
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