Skip to content

Commit

Permalink
TINY-11415: added static service worker (#147)
Browse files Browse the repository at this point in the history
* TINY-11415: added static service worker

* TINY-11415: Fixed jenkinsfile

* TINY-11415: Switched to using node resolve from project root
  • Loading branch information
spocke authored Oct 24, 2024
1 parent 2ecc0d0 commit 9205720
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 11 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 14.1.5 - 2024-10-18

### Added

- Added static mock service worker js file mapping. #TINY-11415

## 14.1.4 - 2024-03-27

### Fixed
Expand Down
38 changes: 27 additions & 11 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,35 @@ timestamps {

stage("test") {
exec('yarn test')

bedrockBrowsers(
prepareTests: {
yarnInstall()
exec('yarn build')
},
testDirs: [ 'modules/sample/src/test/ts/**/pass' ],
custom: '--config modules/sample/tsconfig.json --customRoutes modules/sample/routes.json --polyfills Promise Symbol'
)
}
}

// Testing
stage("bedrock testing") {
bedrockRemoteBrowsers(
platforms: [
[ browser: 'chrome', provider: 'aws', buckets: 2 ],
[ browser: 'firefox', provider: 'aws', buckets: 2 ],
[ browser: 'edge', provider: 'lambdatest', buckets: 1 ],
[ browser: 'chrome', provider: 'lambdatest', os: 'macOS Sonoma', buckets: 1 ],
[ browser: 'firefox', provider: 'lambdatest', os: 'macOS Sonoma', buckets: 1 ],
[ browser: 'safari', provider: 'lambdatest', os: 'macOS Sonoma', buckets: 1 ],
],
prepareTests: {
yarnInstall()
sh 'yarn build'
},
testDirs: [ 'modules/sample/src/test/ts/**/pass' ],
custom: '--config modules/sample/tsconfig.json --customRoutes modules/sample/routes.json --polyfills Promise Symbol'
)
}

if (isReleaseBranch()) {
stage("publish") {
// Publish
if (isReleaseBranch()) {
stage("publish") {
tinyPods.node() {
yarnInstall()
sh 'yarn build'
tinyNpm.withNpmPublishCredentials {
// We need to tell git to ignore the changes to .npmrc when publishing
exec('git update-index --assume-unchanged .npmrc')
Expand Down
23 changes: 23 additions & 0 deletions modules/server/src/main/ts/bedrock/server/Routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,26 @@ export const nodeResolve = (method: HTTPMethod, prefix: string, source: string):
};
};

export const nodeResolveFile = (method: HTTPMethod, url: string, projectDir: string, moduleName: string, subPath: string): Route => {
const go: RouteGoFunc = (request, response, done) => {
const failure = (status: number, data: string) => {
doResponse(request, response, status, 'text/plain', data);
done();
};

try {
const moduleResolvedPath = require.resolve(path.join(moduleName, 'package.json'), { paths: [ projectDir ] });
const router = createServer(path.dirname(moduleResolvedPath));
request.url = '/' + subPath;
router(request, response, done);
} catch (e) {
failure(404, `Failed to resolve static node file for module path: ${moduleName}/${subPath}`);
}
};

return {
matches: [Matchers.methodMatch(method), Matchers.urlMatch(url)],
go
};
};

1 change: 1 addition & 0 deletions modules/server/src/main/ts/bedrock/server/RunnerRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export const generate = async (mode: string, projectdir: string, basedir: string
Routes.routing('GET', '/lib/jquery', path.dirname(require.resolve('jquery'))),
Routes.routing('GET', '/lib/core-js-bundle', path.dirname(require.resolve('core-js-bundle'))),
Routes.routing('GET', '/css', path.join(basedir, 'src/resources/css')),
Routes.nodeResolveFile('GET', '/mockServiceWorker.js', projectdir, 'msw', 'lib/mockServiceWorker.js'),

// test code
Routes.asyncJs('GET', '/compiled/tests.js', (done) => {
Expand Down

0 comments on commit 9205720

Please sign in to comment.