spec/percy/cli/snapshot_spec.rb in percy-cli-1.2.1 vs spec/percy/cli/snapshot_spec.rb in percy-cli-1.2.2
- old
+ new
@@ -1,10 +1,13 @@
require 'digest'
RSpec.describe Percy::Cli::Snapshot do
let(:root_dir) { File.expand_path('../testdata/', __FILE__) }
+ # Used for testing that paths are collapsed before use.r
+ let(:root_dir_relative) { root_dir + '/../testdata' }
+
describe '#run_snapshot' do
xit 'snapshots a root directory of static files' do
# TODO(fotinakis): tests for the full flow.
end
end
@@ -53,39 +56,57 @@
it 'returns only the HTML files in the directory' do
paths = Percy::Cli.new.send(:find_root_paths, root_dir)
expect(paths).to match_array([
File.join(root_dir, 'index.html'),
File.join(root_dir, 'subdir/test.html'),
+ # Make sure file symlinks are followed.
+ File.join(root_dir, 'subdir/test_symlink.html'),
+ # Make sure directory symlinks are followed.
+ File.join(root_dir, 'subdir_symlink/test.html'),
+ File.join(root_dir, 'subdir_symlink/test_symlink.html'),
])
end
end
describe '#find_resource_paths' do
it 'returns only the related static files in the directory' do
paths = Percy::Cli.new.send(:find_resource_paths, root_dir)
expect(paths).to match_array([
File.join(root_dir, 'css/base.css'),
File.join(root_dir, 'css/test with spaces.css'),
File.join(root_dir, 'images/jellybeans.png'),
+ # Make sure file symlinks are followed.
+ File.join(root_dir, 'images/jellybeans-symlink.png'),
+ # Make sure directory symlinks are followed.
+ File.join(root_dir, 'images_symlink/jellybeans.png'),
+ File.join(root_dir, 'images_symlink/jellybeans-symlink.png'),
])
end
end
- describe '#build_resources' do
+ describe '#list_resources' do
it 'returns resource objects' do
paths = [File.join(root_dir, 'css/base.css')]
options = {baseurl: '/', strip_prefix: root_dir}
- resources = Percy::Cli.new.send(:build_resources, paths, options)
+ resources = Percy::Cli.new.send(:list_resources, paths, options)
expect(resources.length).to eq(1)
expect(resources.first.sha).to eq(Digest::SHA256.hexdigest(File.read(paths.first)))
expect(resources.first.is_root).to be_nil
expect(resources.first.content).to be_nil
expect(resources.first.path).to eq(paths.first)
end
+ it 'correctly strips the prefix from resource_url' do
+ paths = [File.join(root_dir, 'index.html')]
+ options = {baseurl: '/', strip_prefix: root_dir_relative, is_root: true}
+ resources = Percy::Cli.new.send(:list_resources, paths, options)
+
+ expect(resources.length).to eq(1)
+ expect(resources.first.resource_url).to eq('/index.html')
+ end
it 'returns resource objects with is_root set if given' do
paths = [File.join(root_dir, 'index.html')]
options = {baseurl: '/', strip_prefix: root_dir, is_root: true}
- resources = Percy::Cli.new.send(:build_resources, paths, options)
+ resources = Percy::Cli.new.send(:list_resources, paths, options)
expect(resources.length).to eq(1)
expect(resources.first.resource_url).to eq('/index.html')
expect(resources.first.sha).to eq(Digest::SHA256.hexdigest(File.read(paths.first)))
expect(resources.first.is_root).to be_truthy
@@ -93,11 +114,11 @@
expect(resources.first.path).to eq(paths.first)
end
it 'encodes the resource_url' do
paths = [File.join(root_dir, 'css/test with spaces.css')]
options = {baseurl: '/', strip_prefix: root_dir}
- resources = Percy::Cli.new.send(:build_resources, paths, options)
+ resources = Percy::Cli.new.send(:list_resources, paths, options)
expect(resources.length).to eq(1)
expect(resources.first.resource_url).to eq('/css/test%20with%20spaces.css')
expect(resources.first.sha).to eq(Digest::SHA256.hexdigest(File.read(paths.first)))
expect(resources.first.is_root).to be_nil
@@ -105,10 +126,10 @@
expect(resources.first.path).to eq(paths.first)
end
it 'prepends the baseurl if given' do
paths = [File.join(root_dir, 'index.html')]
options = {strip_prefix: root_dir, is_root: true, baseurl: '/test baseurl/'}
- resources = Percy::Cli.new.send(:build_resources, paths, options)
+ resources = Percy::Cli.new.send(:list_resources, paths, options)
expect(resources.length).to eq(1)
expect(resources.first.resource_url).to eq('/test%20baseurl/index.html')
expect(resources.first.sha).to eq(Digest::SHA256.hexdigest(File.read(paths.first)))
expect(resources.first.is_root).to be_truthy