Skip to content

Commit

Permalink
Merge pull request #336 from alphagov/v5-package-resolution
Browse files Browse the repository at this point in the history
Preview v5: Update application paths for `govuk-frontend@5`
  • Loading branch information
colinrotherham authored Aug 3, 2023
2 parents acfaaf9 + 6dfd665 commit 095ad64
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
5 changes: 4 additions & 1 deletion lib/sassdocs_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,11 @@ def subgroup_heading(heading)
end

def github_url(item)
# Maintain backwards compatibility with GOV.UK Frontend v4
github_package_path = govuk_frontend_version.start_with?("4") ? "/src" : "/packages/govuk-frontend/src"

# Construct GitHub link
"https://github.com/alphagov/govuk-frontend/tree/v#{govuk_frontend_version}/src/govuk/#{item.file.path}#L#{item.context.line.start}-L#{item.context.line.end}"
"https://github.com/alphagov/govuk-frontend/tree/v#{govuk_frontend_version}#{github_package_path}/govuk/#{item.file.path}#L#{item.context.line.start}-L#{item.context.line.end}"
end

def govuk_frontend_version
Expand Down
24 changes: 19 additions & 5 deletions spec/sassdocs_helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ def dothash(hash)
end

RSpec.describe SassdocsHelpers do
let(:package_version) { "5.0.0" }
let(:package_content) { sprintf('{ "packages": { "node_modules/govuk-frontend": { "version": "%s" } } }', package_version) }

before(:each) do
allow(File).to receive(:read).and_return('{ "packages": { "node_modules/govuk-frontend": { "version": "1.0.0" } } }')
allow(File).to receive(:read).and_return(package_content)
# Include mixin into a test class to allow us to mock File
# TODO Move constant definition
# rubocop:disable Lint/ConstantDefinitionInBlock
Expand Down Expand Up @@ -323,8 +326,8 @@ class Test
end
end
describe "#github_url" do
it "returns a url" do
fixture = dothash({
let(:fixture) do
dothash({
context: {
line: {
start: 9,
Expand All @@ -335,16 +338,27 @@ class Test
path: "helpers/_clearfix.scss",
},
})
end

it "returns a url" do
url = @helper.github_url(fixture)
expect(url).to eq("https://github.com/alphagov/govuk-frontend/tree/v5.0.0/packages/govuk-frontend/src/govuk/helpers/_clearfix.scss#L9-L15")
end

describe "v4.x backwards compatibility" do
let(:package_version) { "4.0.0" }

expect(url).to eq("https://github.com/alphagov/govuk-frontend/tree/v1.0.0/src/govuk/helpers/_clearfix.scss#L9-L15")
it "returns a url" do
url = @helper.github_url(fixture)
expect(url).to eq("https://github.com/alphagov/govuk-frontend/tree/v4.0.0/src/govuk/helpers/_clearfix.scss#L9-L15")
end
end
end
describe "#govuk_frontend_version" do
it "returns version" do
version = @helper.govuk_frontend_version

expect(version).to eq("1.0.0")
expect(version).to eq("5.0.0")
end
end
end

0 comments on commit 095ad64

Please sign in to comment.