Skip to content

Commit 9632203

Browse files
authored
[WORLDSERVICE-464] Remove sw.js for Public Services (#12566)
* refactor: remove sw.js for Public Service * test: update service worker tests to reflect non-WS * refactor: remove Public Service related regex for getArticleSwRegex; update tests * refactor: remove getArticleSwRegex, getArticleManifestRegex and related code * test: re-enable e2e test; remove outdated tests * refactor: keep sw test; remove array wrapper
1 parent f1b5a25 commit 9632203

File tree

9 files changed

+17
-96
lines changed

9 files changed

+17
-96
lines changed
Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,6 @@ describe('Application', () => {
2323
});
2424
});
2525

26-
it(`should return a 200 status code for ${service}'s article service worker`, () => {
27-
cy.testResponseCodeAndType({
28-
path: `/${config[service].name}/articles/sw.js`,
29-
responseCode: 200,
30-
type: 'application/javascript',
31-
});
32-
});
33-
3426
it(`should return a 200 status code for ${service} manifest file`, () => {
3527
cy.testResponseCodeAndType({
3628
path: `/${config[service].name}/manifest.json`,
@@ -39,14 +31,6 @@ describe('Application', () => {
3931
});
4032
});
4133

42-
it(`should return a 200 status code for ${service} article manifest file`, () => {
43-
cy.testResponseCodeAndType({
44-
path: `/${config[service].name}/articles/manifest.json`,
45-
responseCode: 200,
46-
type: 'application/json',
47-
});
48-
});
49-
5034
it(`should awaken fresh data for pages for later tests`, () => {
5135
// Add more here if you want to awaken fresh data for other page types
5236
if (serviceHasPageType(service, 'topicPage')) {

src/app/lib/config/services/archive.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ export const service: DefaultServiceConfig = {
3737
publishingPrinciples: null,
3838
isTrustProjectParticipant: false,
3939
script: latin,
40-
swPath: '/articles/sw.js',
4140
homePageTitle: 'Home',
4241
showAdPlaceholder: false,
4342
showRelatedTopics: true,

src/app/lib/config/services/scotland.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ export const service: DefaultServiceConfig = {
3838
publishingPrinciples: null,
3939
isTrustProjectParticipant: false,
4040
script: latin,
41-
swPath: '/articles/sw.js',
4241
homePageTitle: 'Home',
4342
passportHomes: ['BBCScotland'],
4443
showAdPlaceholder: false,

src/app/routes/utils/regex/index.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import services from '../../../lib/config/services/loadableConfig';
22
import {
33
getArticleRegex,
4-
getArticleSwRegex,
5-
getArticleManifestRegex,
64
getHomePageRegex,
75
getSwRegex,
86
getManifestRegex,
@@ -27,9 +25,6 @@ const allServices = Object.keys(services);
2725
export const articlePath = getArticleRegex(allServices);
2826
export const articleDataPath = `${articlePath}.json`;
2927

30-
export const articleSwPath = getArticleSwRegex(allServices);
31-
export const articleManifestPath = getArticleManifestRegex(allServices);
32-
3328
export const homePageSwPath = getSwRegex(allServices);
3429
export const homePageManifestPath = getManifestRegex(allServices);
3530
export const homePagePath = getHomePageRegex(allServices);

src/app/routes/utils/regex/index.test.js

Lines changed: 5 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import { matchPath } from 'react-router-dom';
22
import {
33
articleDataPath,
4-
articleManifestPath,
54
articlePath,
6-
articleSwPath,
75
cpsAssetPageDataPath,
86
cpsAssetPagePath,
97
homePagePath,
@@ -124,55 +122,16 @@ describe('homePageDataPath', () => {
124122
shouldNotMatchInvalidRoutes(invalidRoutes, homePageDataPath);
125123
});
126124

127-
describe('articleSwPath', () => {
128-
const validRoutes = [
129-
'/news/articles/sw.js',
130-
'/persian/articles/sw.js',
131-
'/cymrufyw/erthyglau/sw.js',
132-
];
133-
shouldMatchValidRoutes(validRoutes, articleSwPath);
134-
135-
const invalidRoutes = [
136-
'/news/sw.js',
137-
'/persian/articles/sw',
138-
'/news/trad/sw.js',
139-
'/cymrufyw/sw.js',
140-
];
141-
shouldNotMatchInvalidRoutes(invalidRoutes, articleSwPath);
142-
});
143-
144-
describe('articleManifestPath', () => {
145-
const validRoutes = [
146-
'/persian/articles/manifest.json',
147-
'/serbian/articles/manifest.json',
148-
];
149-
shouldMatchValidRoutes(validRoutes, articleManifestPath);
150-
151-
const invalidRoutes = [
152-
'/news/articles/manifest.json',
153-
'/sport/articles/manifest.json',
154-
'/naidheachdan/sgeulachdan/manifest.json',
155-
'/cymrufyw/erthyglau/manifest.json',
156-
'/newsround/articles/manifest.json',
157-
'/news/manifest.json',
158-
'/sport/manifest.json',
159-
'/naidheachdan/manifest.json',
160-
'/cymrufyw/manifest.json',
161-
'/newsround/manifest.json',
162-
'/persian/articles/manifest',
163-
'/news/simp/sw.js',
164-
];
165-
shouldNotMatchInvalidRoutes(invalidRoutes, articleManifestPath);
166-
});
167-
168125
describe('homePageSwPath', () => {
169-
const validRoutes = ['/news/sw.js', '/persian/sw.js'];
126+
const validRoutes = ['/gahuza/sw.js', '/persian/sw.js'];
170127
shouldMatchValidRoutes(validRoutes, homePageSwPath);
171128

172129
const invalidRoutes = [
130+
'/news/sw.js',
173131
'/news/articles/sw.js',
174132
'/persian/sw',
175133
'/persian/simp/sw.js',
134+
'/gahuza/articles/sw.js',
176135
];
177136
shouldNotMatchInvalidRoutes(invalidRoutes, homePageSwPath);
178137
});
@@ -190,6 +149,8 @@ describe('homePageManifestPath', () => {
190149
'/foobar/manifest.json',
191150
'/foobar/manifest',
192151
'/news/trad/sw.js',
152+
'/persian/articles/manifest.json',
153+
'/serbian/articles/manifest.json',
193154
];
194155
shouldNotMatchInvalidRoutes(invalidRoutes, homePageManifestPath);
195156
});

src/app/routes/utils/regex/utils/__snapshots__/index.test.js.snap

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@
22

33
exports[`regex utils snapshots should create expected regex from getAfricaEyeTVPageRegex 1`] = `"/worldservice/tv/africa_eye/:episodeId([a-z0-9]+)?:lite(.lite)?"`;
44

5-
exports[`regex utils snapshots should create expected regex from getArticleManifestRegex 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|azeri|bengali|burmese|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|nepali|pashto|persian|pidgin|portuguese|punjabi|russian|scotland|serbian|sinhala|somali|swahili|tamil|telugu|thai|tigrinya|turkce|ukchina|ukrainian|urdu|uzbek|vietnamese|ws|yoruba|zhongwen)/:local(articles|erthyglau|sgeulachdan)/manifest.json"`;
6-
75
exports[`regex utils snapshots should create expected regex from getArticleRegex 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|archive|azeri|bengali|burmese|cymrufyw|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|naidheachdan|nepali|news|newsround|pashto|persian|pidgin|portuguese|punjabi|russian|scotland|serbian|sinhala|somali|sport|swahili|tamil|telugu|thai|tigrinya|turkce|ukchina|ukrainian|urdu|uzbek|vietnamese|ws|yoruba|zhongwen)?:discipline(/[a-z0-9-_]{1,})?/:local(articles|erthyglau|sgeulachdan)/:id(c[a-zA-Z0-9]{10}o):variant(/simp|/trad|/cyr|/lat)?:nonCanonicalArticleRenderPlatform(.amp|.app|.lite)?"`;
86

9-
exports[`regex utils snapshots should create expected regex from getArticleSwRegex 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|archive|azeri|bengali|burmese|cymrufyw|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|naidheachdan|nepali|news|newsround|pashto|persian|pidgin|portuguese|punjabi|russian|scotland|serbian|sinhala|somali|sport|swahili|tamil|telugu|thai|tigrinya|turkce|ukchina|ukrainian|urdu|uzbek|vietnamese|ws|yoruba|zhongwen)/:local(articles|erthyglau|sgeulachdan)/sw.js"`;
10-
117
exports[`regex utils snapshots should create expected regex from getCpsAssetRegex 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|archive|azeri|bengali|burmese|cymrufyw|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|naidheachdan|nepali|news|newsround|pashto|persian|pidgin|portuguese|punjabi|russian|scotland|serbian|sinhala|somali|sport|swahili|tamil|telugu|thai|tigrinya|turkce|ukchina|ukrainian|urdu|uzbek|vietnamese|ws|yoruba|zhongwen):variant(/simp|/trad|/cyr|/lat)?/:assetUri([a-z0-9-_+]{0,}[0-9]{8,}):amp(.amp)?:lite(.lite)?"`;
128

139
exports[`regex utils snapshots should create expected regex from getErrorPageRegex 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|archive|azeri|bengali|burmese|cymrufyw|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|naidheachdan|nepali|news|newsround|pashto|persian|pidgin|portuguese|punjabi|russian|scotland|serbian|sinhala|somali|sport|swahili|tamil|telugu|thai|tigrinya|turkce|ukchina|ukrainian|urdu|uzbek|vietnamese|ws|yoruba|zhongwen)/:errorCode(404|500):variant(/simp|/trad|/cyr|/lat)?:lite(.lite)?"`;
@@ -18,7 +14,7 @@ exports[`regex utils snapshots should create expected regex from getLegacyAssetR
1814

1915
exports[`regex utils snapshots should create expected regex from getLiveRadioRegex 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|archive|azeri|bengali|burmese|cymrufyw|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|naidheachdan|nepali|news|newsround|pashto|persian|pidgin|portuguese|punjabi|russian|scotland|serbian|sinhala|somali|sport|swahili|tamil|telugu|thai|tigrinya|turkce|ukchina|ukrainian|urdu|uzbek|vietnamese|ws|yoruba|zhongwen)/:masterBrand(bbc_[a-z]+_radio)/:mediaId(liveRadio):lite(.lite)?"`;
2016

21-
exports[`regex utils snapshots should create expected regex from getManifestRegex 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|azeri|bengali|burmese|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|nepali|pashto|persian|pidgin|portuguese|punjabi|russian|scotland|serbian|sinhala|somali|swahili|tamil|telugu|thai|tigrinya|turkce|ukchina|ukrainian|urdu|uzbek|vietnamese|ws|yoruba|zhongwen)/manifest.json"`;
17+
exports[`regex utils snapshots should create expected regex from getManifestRegex 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|azeri|bengali|burmese|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|nepali|pashto|persian|pidgin|portuguese|punjabi|russian|serbian|sinhala|somali|swahili|tamil|telugu|thai|tigrinya|turkce|ukchina|ukrainian|urdu|uzbek|vietnamese|ws|yoruba|zhongwen)/manifest.json"`;
2218

2319
exports[`regex utils snapshots should create expected regex from getMostReadDataRegex 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|archive|azeri|bengali|burmese|cymrufyw|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|naidheachdan|nepali|news|newsround|pashto|persian|pidgin|portuguese|punjabi|russian|scotland|serbian|sinhala|somali|sport|swahili|tamil|telugu|thai|tigrinya|turkce|ukchina|ukrainian|urdu|uzbek|vietnamese|ws|yoruba|zhongwen)/mostread:variant(/simp|/trad|/cyr|/lat)?.json"`;
2420

@@ -36,6 +32,6 @@ exports[`regex utils snapshots should create expected regex from getRecommendati
3632

3733
exports[`regex utils snapshots should create expected regex from getSecondaryColumnDataRegex 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|archive|azeri|bengali|burmese|cymrufyw|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|naidheachdan|nepali|news|newsround|pashto|persian|pidgin|portuguese|punjabi|russian|scotland|serbian|sinhala|somali|sport|swahili|tamil|telugu|thai|tigrinya|turkce|ukchina|ukrainian|urdu|uzbek|vietnamese|ws|yoruba|zhongwen)/sty-secondary-column:variant(/simp|/trad|/cyr|/lat)?.json"`;
3834

39-
exports[`regex utils snapshots should create expected regex from getSwRegex 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|archive|azeri|bengali|burmese|cymrufyw|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|naidheachdan|nepali|news|newsround|pashto|persian|pidgin|portuguese|punjabi|russian|scotland|serbian|sinhala|somali|sport|swahili|tamil|telugu|thai|tigrinya|turkce|ukchina|ukrainian|urdu|uzbek|vietnamese|ws|yoruba|zhongwen)/sw.js"`;
35+
exports[`regex utils snapshots should create expected regex from getSwRegex 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|azeri|bengali|burmese|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|nepali|pashto|persian|pidgin|portuguese|punjabi|russian|serbian|sinhala|somali|swahili|tamil|telugu|thai|tigrinya|turkce|ukchina|ukrainian|urdu|uzbek|vietnamese|ws|yoruba|zhongwen)/sw.js"`;
4036

4137
exports[`regex utils snapshots should create expected regex from getTopicPageRegex 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|archive|azeri|bengali|burmese|cymrufyw|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|naidheachdan|nepali|news|newsround|pashto|persian|pidgin|portuguese|punjabi|russian|scotland|serbian|sinhala|somali|sport|swahili|tamil|telugu|thai|tigrinya|turkce|ukchina|ukrainian|urdu|uzbek|vietnamese|ws|yoruba|zhongwen)/topics/:id([a-z0-9]+)?:variant(/simp|/trad|/cyr|/lat)?:lite(.lite)?"`;

src/app/routes/utils/regex/utils/index.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@ export const getArticleRegex = services => {
2222
return `/:service(${serviceRegex})?:discipline(${sportDisciplineRegex})?/:local(${articleLocalRegex})/:id(${idRegex}):variant(${variantRegex})?:nonCanonicalArticleRenderPlatform(${nonCanonicalArticleRenderPlatform})?`;
2323
};
2424

25-
export const getArticleSwRegex = services => {
26-
const serviceRegex = getServiceRegex(services);
27-
return `/:service(${serviceRegex})/:local(${articleLocalRegex})/sw.js`;
28-
};
29-
3025
const getWorldServices = services => {
3126
const publicServices = [
3227
'news',
@@ -35,23 +30,19 @@ const getWorldServices = services => {
3530
'cymrufyw',
3631
'naidheachdan',
3732
'archive',
33+
'scotland',
3834
];
3935

4036
return services.filter(service => !publicServices.includes(service));
4137
};
4238

43-
export const getArticleManifestRegex = services => {
44-
const serviceRegex = getServiceRegex(getWorldServices(services));
45-
return `/:service(${serviceRegex})/:local(${articleLocalRegex})/manifest.json`;
46-
};
47-
4839
export const getHomePageRegex = services => {
4940
const homePageServiceRegex = getServiceRegex(services);
5041
return `/:service(${homePageServiceRegex}):variant(${variantRegex})?:lite(${liteRegex})?`;
5142
};
5243

5344
export const getSwRegex = services => {
54-
const serviceRegex = getServiceRegex(services);
45+
const serviceRegex = getServiceRegex(getWorldServices(services));
5546
return `/:service(${serviceRegex})/sw.js`;
5647
};
5748

src/server/index.jsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ import injectCspHeader from './utilities/cspHeader';
2323
import logResponseTime from './utilities/logResponseTime';
2424
import renderDocument from './Document';
2525
import {
26-
articleManifestPath,
27-
articleSwPath,
2826
homePageManifestPath,
2927
homePageSwPath,
3028
} from '../app/routes/utils/regex';
@@ -112,7 +110,7 @@ server
112110
* Application env routes
113111
*/
114112
server
115-
.get([articleSwPath, homePageSwPath], (req, res) => {
113+
.get(homePageSwPath, (req, res) => {
116114
const swPath = `${__dirname}/public/sw.js`;
117115
res.set(
118116
`Cache-Control`,
@@ -125,7 +123,7 @@ server
125123
}
126124
});
127125
})
128-
.get([articleManifestPath, homePageManifestPath], async ({ params }, res) => {
126+
.get(homePageManifestPath, async ({ params }, res) => {
129127
const { service } = params;
130128
const variant = defaultServiceVariants[service] || 'default';
131129
const manifestPath = `${__dirname}/public${serviceConfigs[service][variant].manifestPath}`;

src/server/index.test.jsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -953,14 +953,14 @@ describe('Server', () => {
953953

954954
describe('Service workers', () => {
955955
it('should serve a file for existing service workers', async () => {
956-
await makeRequest('/news/articles/sw.js');
956+
await makeRequest('/gahuza/sw.js');
957957
expect(sendFileSpy.mock.calls[0][0]).toEqual(
958958
path.join(__dirname, '/public/sw.js'),
959959
);
960960
});
961961

962962
it('should not serve a file for non-existing service workers', async () => {
963-
const { statusCode } = await makeRequest('/some-service/articles/sw.js');
963+
const { statusCode } = await makeRequest('/news/sw.js');
964964
expect(sendFileSpy.mock.calls.length).toEqual(0);
965965
expect(statusCode).toEqual(500);
966966
});
@@ -975,11 +975,9 @@ describe('Server', () => {
975975

976976
describe('Manifest json', () => {
977977
it.each`
978-
manifestPath | expectedManifestFile
979-
${'/pidgin/articles/manifest.json'} | ${'/pidgin/manifest.json'}
980-
${'/pidgin/manifest.json'} | ${'/pidgin/manifest.json'}
981-
${'/serbian/articles/manifest.json'} | ${'/serbian/manifest.json'}
982-
${'/serbian/manifest.json'} | ${'/serbian/manifest.json'}
978+
manifestPath | expectedManifestFile
979+
${'/pidgin/manifest.json'} | ${'/pidgin/manifest.json'}
980+
${'/serbian/manifest.json'} | ${'/serbian/manifest.json'}
983981
`(
984982
'should serve a file for $manifestPath',
985983
async ({ manifestPath, expectedManifestFile }) => {
@@ -997,7 +995,7 @@ describe('Server', () => {
997995
});
998996

999997
it('should serve a response cache control of 1 day', async () => {
1000-
const { header } = await makeRequest('/pidgin/articles/manifest.json');
998+
const { header } = await makeRequest('/pidgin/manifest.json');
1001999
expect(header['cache-control']).toBe(
10021000
'public, stale-if-error=172800, stale-while-revalidate=172800, max-age=86400',
10031001
);

0 commit comments

Comments
 (0)