Skip to content
This repository was archived by the owner on Nov 30, 2021. It is now read-only.

Commit 82be4b6

Browse files
author
Alistair Laing
committed
Scenario: A user has an existing prototype and tries to follow our
standard upgrade path but fails to copy the changes made in `/app` - Stylesheets > Still uses node_modules directly in the backend before being compiled to application.css - scripts > `govuk-frontend/all.js` was not loading in the browser. I had to reintroduce the route to `node_modules/govuk-frontend` to server.js so that the file could be served to the browser. I have written tests for this scenario to ensure it is not an issue in the future. It could be tidied up once we finalise extensions and move it out of experimental.
1 parent 2554556 commit 82be4b6

2 files changed

Lines changed: 60 additions & 38 deletions

File tree

__tests__/spec/sanity-checks.js

Lines changed: 57 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -45,46 +45,65 @@ describe('The Prototype Kit', () => {
4545
})
4646
})
4747

48-
it('should allow known assets to be loaded from node_modules', function (done) {
49-
request(app)
50-
.get('/extension-assets/govuk-frontend/all.js')
51-
.expect('Content-Type', /application\/javascript; charset=UTF-8/)
52-
.expect(200)
53-
.end(function (err, res) {
54-
if (err) {
55-
done(err)
56-
} else {
57-
assert.strictEqual('' + res.text, readFile('node_modules/govuk-frontend/all.js'))
58-
done()
59-
}
60-
})
61-
})
48+
describe('extensions', () => {
49+
it('should allow known assets to be loaded from node_modules', (done) => {
50+
request(app)
51+
.get('/extension-assets/govuk-frontend/all.js')
52+
.expect('Content-Type', /application\/javascript; charset=UTF-8/)
53+
.expect(200)
54+
.end(function (err, res) {
55+
if (err) {
56+
done(err)
57+
} else {
58+
assert.strictEqual('' + res.text, readFile('node_modules/govuk-frontend/all.js'))
59+
done()
60+
}
61+
})
62+
})
6263

63-
it('should allow known assets to be loaded from node_modules', function (done) {
64-
request(app)
65-
.get('/assets/images/favicon.ico')
66-
.expect('Content-Type', /image\/x-icon/)
67-
.expect(200)
68-
.end(function (err, res) {
69-
if (err) {
70-
done(err)
71-
} else {
72-
assert.strictEqual('' + res.body, readFile('node_modules/govuk-frontend/assets/images/favicon.ico'))
73-
done()
74-
}
75-
})
76-
})
64+
it('should allow known assets to be loaded from node_modules', (done) => {
65+
request(app)
66+
.get('/assets/images/favicon.ico')
67+
.expect('Content-Type', /image\/x-icon/)
68+
.expect(200)
69+
.end(function (err, res) {
70+
if (err) {
71+
done(err)
72+
} else {
73+
assert.strictEqual('' + res.body, readFile('node_modules/govuk-frontend/assets/images/favicon.ico'))
74+
done()
75+
}
76+
})
77+
})
78+
79+
it('should not expose everything', function (done) {
80+
request(app)
81+
.get('/assets/common.js')
82+
.expect(404)
83+
.end(function (err, res) {
84+
if (err) {
85+
done(err)
86+
} else {
87+
done()
88+
}
89+
})
90+
})
7791

78-
it('should not expose everything', function (done) {
79-
request(app)
80-
.get('/assets/common.js')
81-
.expect(404)
82-
.end(function (err, res) {
83-
if (err) {
84-
done(err)
85-
} else {
86-
done()
87-
}
92+
describe('misconfigured prototype kit - while upgrading kit developer did not copy over changes in /app folder', () => {
93+
it('should still allow known assets to be loaded from node_modules', (done) => {
94+
request(app)
95+
.get('/node_modules/govuk-frontend/all.js')
96+
.expect('Content-Type', /application\/javascript; charset=UTF-8/)
97+
.expect(200)
98+
.end(function (err, res) {
99+
if (err) {
100+
done(err)
101+
} else {
102+
assert.strictEqual('' + res.text, readFile('node_modules/govuk-frontend/all.js'))
103+
done()
104+
}
105+
})
88106
})
107+
})
89108
})
90109
})

server.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ app.set('view engine', 'html')
111111
// Middleware to serve static assets
112112
app.use('/public', express.static(path.join(__dirname, '/public')))
113113

114+
// Serve govuk-frontend in from node_modules (so not to break pre-extenstions prototype kits)
115+
app.use('/node_modules/govuk-frontend', express.static(path.join(__dirname, '/node_modules/govuk-frontend')))
116+
114117
// Set up documentation app
115118
if (useDocumentation) {
116119
var documentationViews = [

0 commit comments

Comments
 (0)