-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move the MRT reference app to the SDKs, so that we can verify eg. Node support #966
Changes from 11 commits
2b3b68d
d428c81
80ed3cf
e5fcd1a
de2c823
31bd3cd
775a972
c08d78b
46d9b34
caf5812
39e15af
f483768
fbe201b
c85e83e
d3d2283
4875641
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -738,59 +738,24 @@ describe('DevServer service worker', () => { | |
|
||
test(`${name} (and handle 404s correctly)`, () => { | ||
const app = createApp() | ||
app.get('/worker.js(.map)?', NoWebpackDevServerFactory.serveServiceWorker) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test had a bug where it didn't actually run |
||
|
||
return request(app).get(requestPath).expect(404) | ||
}) | ||
}) | ||
}) | ||
|
||
describe('DevServer serveStaticFile', () => { | ||
// This isn't ideal! We need a way to test the dev middleware | ||
// including the on demand webpack compiler. However, the webpack config and | ||
// the Dev server assumes the code runs at the root of a project. | ||
// When we run the tests, we are not in a project. | ||
// We have a /test_fixtures project, but Jest does not support process.chdir(), | ||
// nor mocking process.cwd(), so we mock the dev middleware for now. | ||
// TODO: create a proper testing fixture project and run the tests in the isolated | ||
// project environment. | ||
const MockWebpackDevMiddleware = { | ||
waitUntilValid: (cb) => cb(), | ||
context: { | ||
stats: { | ||
stats: [ | ||
{ | ||
compilation: { | ||
name: 'server', | ||
assetsInfo: new Map([ | ||
[ | ||
'static/favicon.ico', | ||
{ | ||
sourceFilename: path.resolve( | ||
testFixtures, | ||
'app/static/favicon.ico' | ||
) | ||
} | ||
] | ||
]) | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} | ||
|
||
test('should serve static files', async () => { | ||
const options = opts() | ||
const options = opts({projectDir: testFixtures}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I made this configurable, so we don't have to do this middleware mocking. |
||
const app = NoWebpackDevServerFactory._createApp(options) | ||
app.__devMiddleware = MockWebpackDevMiddleware | ||
app.use('/test', NoWebpackDevServerFactory.serveStaticFile('static/favicon.ico')) | ||
return request(app).get('/test').expect(200) | ||
}) | ||
|
||
test('should return 404 if static file does not exist', async () => { | ||
const options = opts() | ||
const options = opts({projectDir: testFixtures}) | ||
const app = NoWebpackDevServerFactory._createApp(options) | ||
app.__devMiddleware = MockWebpackDevMiddleware | ||
app.use('/test', NoWebpackDevServerFactory.serveStaticFile('static/IDoNotExist.ico')) | ||
return request(app).get('/test').expect(404) | ||
}) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
build | ||
coverage | ||
docs | ||
app/static | ||
jest.config.js | ||
webpack | ||
scripts/generator/assets |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
* Copyright (c) 2021, salesforce.com, inc. | ||
* All rights reserved. | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
module.exports = { | ||
extends: require.resolve('pwa-kit-dev/configs/eslint/eslint-config') | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
build | ||
node_modules | ||
build.tar |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
build | ||
docs | ||
coverage | ||
scripts/generator/assets |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
printWidth: 100 | ||
singleQuote: true | ||
semi: false | ||
bracketSpacing: false | ||
tabWidth: 4 | ||
arrowParens: 'always' | ||
trailingComma: 'none' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
BSD 3-Clause License | ||
|
||
Copyright (c) 2021, Salesforce.com, Inc. | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: | ||
|
||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. | ||
|
||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. | ||
|
||
3. Neither the name of Salesforce.com nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# template-mrt-reference-app | ||
|
||
This is the reference app that the Managed Runtime Team uses to test | ||
features in the platform (eg. TLS versions, successful deploys, proxy | ||
behaviour). | ||
|
||
This app is intended to be a thin layer over the bare minimum SDKs | ||
that we expect/require all MRT users to use. | ||
|
||
Although MRT started life primarily as a hosting environment for | ||
React apps, we're expanding that to support other technologies – | ||
this app lets us test those platform features that are universal | ||
across all apps, regardless of framework choice. | ||
|
||
|
||
## Usage in CI/CD tests ⛅️ | ||
|
||
This app is deployed to several pre-existing test Targets as part | ||
of a "smoke-test" of the MRT platform. To see the Targets in use | ||
take a look at the CI config in | ||
|
||
https://git.soma.salesforce.com/cc-mobify/ssr-infrastructure/blob/sfci-main/Jenkinsfile#L176 | ||
|
||
These smoke-tests are triggered by merges to the main development | ||
branch of the above repository. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright (c) 2023, Salesforce, Inc. | ||
* All rights reserved. | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
import {QueryParameters} from 'pwa-kit-runtime/utils/ssr-request-processing' | ||
|
||
const exclusions = ['removeme'] | ||
|
||
export const processRequest = ({path, querystring, parameters}) => { | ||
console.assert(parameters, 'Missing parameters') | ||
|
||
// Query string filtering | ||
|
||
// Build a first QueryParameters object from the given querystring | ||
const queryParameters = new QueryParameters(querystring) | ||
|
||
// Build a second QueryParameters from the first, with all | ||
// excluded parameters removed | ||
const filtered = QueryParameters.from( | ||
queryParameters.parameters.filter( | ||
// parameter.key is always lower-case | ||
(parameter) => !exclusions.includes(parameter.key) | ||
) | ||
) | ||
|
||
// Re-generate the querystring | ||
querystring = filtered.toString() | ||
|
||
return { | ||
path, | ||
querystring | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turns out, it's this config that is really always mandatory. My bad!