|
| 1 | +require 'spec_helper' |
| 2 | + |
| 3 | +describe Overcommit::Hook::PreCommit::YarnCheck do |
| 4 | + let(:config) { Overcommit::ConfigurationLoader.default_configuration } |
| 5 | + let(:context) { double('context') } |
| 6 | + subject { described_class.new(config, context) } |
| 7 | + |
| 8 | + context 'when yarn.lock is ignored' do |
| 9 | + around do |example| |
| 10 | + repo do |
| 11 | + touch 'yarn.lock' |
| 12 | + echo('yarn.lock', '.gitignore') |
| 13 | + `git add .gitignore` |
| 14 | + `git commit -m "Ignore yarn.lock"` |
| 15 | + example.run |
| 16 | + end |
| 17 | + end |
| 18 | + |
| 19 | + it { should pass } |
| 20 | + end |
| 21 | + |
| 22 | + context 'when yarn.lock is not ignored' do |
| 23 | + let(:result) { double('result') } |
| 24 | + |
| 25 | + around do |example| |
| 26 | + repo do |
| 27 | + example.run |
| 28 | + end |
| 29 | + end |
| 30 | + |
| 31 | + before do |
| 32 | + result.stub(stderr: stderr) |
| 33 | + subject.stub(:execute).with(%w[git ls-files -o -i --exclude-standard]). |
| 34 | + and_return(double(stdout: '')) |
| 35 | + subject.stub(:execute).with(%w[yarn check --silent --no-progress --non-interactive]). |
| 36 | + and_return(result) |
| 37 | + end |
| 38 | + |
| 39 | + context 'and yarn check reports no errors' do |
| 40 | + let(:stderr) { '' } |
| 41 | + |
| 42 | + it { should pass } |
| 43 | + |
| 44 | + context 'and there was a change to the yarn.lock' do |
| 45 | + before do |
| 46 | + subject.stub(:execute).with(%w[yarn check --silent --no-progress --non-interactive]) do |
| 47 | + echo('stuff', 'yarn.lock') |
| 48 | + double(stderr: '') |
| 49 | + end |
| 50 | + end |
| 51 | + |
| 52 | + it { should fail_hook } |
| 53 | + end |
| 54 | + end |
| 55 | + |
| 56 | + context 'and yarn check contains only warnings' do |
| 57 | + let(:stderr) do |
| 58 | + <<STDERR |
| 59 | +warning "parent-package#child-package@version" could be deduped from "one version" to "another version" |
| 60 | +STDERR |
| 61 | + end |
| 62 | + |
| 63 | + it { should pass } |
| 64 | + end |
| 65 | + |
| 66 | + context 'and yarn check contains unactionable errors' do |
| 67 | + let(:stderr) do |
| 68 | + <<STDERR |
| 69 | +error "peer-dependency#peer@a || list || of || versions" doesn't satisfy found match of "peer@different-version" |
| 70 | +error "bad-maintainer#bad-package" is wrong version: expected "something normal", got "something crazy" |
| 71 | +STDERR |
| 72 | + end |
| 73 | + |
| 74 | + it { should pass } |
| 75 | + end |
| 76 | + |
| 77 | + context 'and yarn check contains actionable errors' do |
| 78 | + let(:stderr) do |
| 79 | + <<STDERR |
| 80 | +error Lockfile does not contain pattern: "thing-i-updated-in-package.json@new-version" |
| 81 | +STDERR |
| 82 | + end |
| 83 | + |
| 84 | + it { should fail_hook } |
| 85 | + end |
| 86 | + end |
| 87 | +end |
0 commit comments