Skip to content

Commit

Permalink
chore: export mocks (#3607)
Browse files Browse the repository at this point in the history
OKTA-719095 chore: export mocks
remove out workspace dep
  • Loading branch information
shuowu-okta committed Apr 18, 2024
1 parent b1b7ff5 commit 59284e9
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 9 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
"default": "./target/js/okta-sign-in.oie.js"
},
"./polyfill": "./target/js/okta-sign-in.polyfill.js",
"./css/": "./target/css/"
"./css/": "./target/css/",
"./mocks": "./playground/mocks/server.js"
},
"scripts": {
"clean": "rimraf target && rimraf dist && rimraf build2",
Expand Down
5 changes: 2 additions & 3 deletions playground/mocks/config/templateHelper.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const path = require('path');
const responseConfig = require('./responseConfig');
const signinWidgetOptions = require('../../../.widgetrc.js');
const supportedApi = [
'/oauth2/',
'/api/v1/authn',
Expand Down Expand Up @@ -45,7 +44,7 @@ const configMock = (option) => {
proxy: false,
method: option.method || 'POST',
status: (req, res, next) => {
if(!hasChainedMockData) {
if (!hasChainedMockData) {
res.status(403);
next();
return;
Expand Down Expand Up @@ -78,7 +77,7 @@ const configMock = (option) => {

// overwrite URLs if using mock server behind the proxy
const json = require(mockFile);
const str = JSON.stringify(json).replace(/http:\/\/localhost:3000/g, signinWidgetOptions.baseUrl);
const str = JSON.stringify(json).replace(/http:\/\/localhost:3000/g, process.env.BASE_URL);
return JSON.parse(str);
}

Expand Down
6 changes: 5 additions & 1 deletion playground/mocks/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"name": "@okta/mocks",
"version": "1.0.0",
"private": "true"
"private": "true",
"main": "server.js",
"dependencies": {
"dyson": "^4.1.0"
}
}
2 changes: 1 addition & 1 deletion playground/mocks/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ const app = dyson.createServer(options);
dyson.registerServices(app, options, configs);

// eslint-disable-next-line no-console
console.log( '\x1b[32m%s\x1b[0m', 'Dyson mock server started');
console.log('\x1b[32m%s\x1b[0m', 'Dyson mock server started at port:', options.port);
2 changes: 1 addition & 1 deletion src/v3/webpack.dev.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ const devConfig: Configuration = mergeWithRules({
setupMiddlewares(middlewares) {
const script = resolve(PLAYGROUND, 'mocks/server.js');
const watch = [resolve(PLAYGROUND, 'mocks')];
const env = { MOCK_SERVER_PORT, DEV_SERVER_PORT };
const env = { MOCK_SERVER_PORT, DEV_SERVER_PORT, BASE_URL: require(WIDGET_RC_JS).baseUrl };

nodemon({
script, watch, env, delay: 50,
Expand Down
4 changes: 2 additions & 2 deletions webpack.playground.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const headers = {};
if (!process.env.DISABLE_CSP) {
// Allow google domains for testing recaptcha
const scriptSrc = `script-src http://${HOST}:${DEV_SERVER_PORT} 'nonce-playground' https://www.google.com https://www.gstatic.com`;
const styleSrc = `style-src http://${HOST}:${DEV_SERVER_PORT} 'nonce-playground'`;
const styleSrc = `style-src http://${HOST}:${DEV_SERVER_PORT} 'nonce-playground'`;
const csp = `${scriptSrc}; ${styleSrc};`;
headers['Content-Security-Policy'] = csp;
}
Expand Down Expand Up @@ -140,7 +140,7 @@ module.exports = {
setupMiddlewares(middlewares) {
const script = path.resolve(__dirname, 'playground/mocks/server.js');
const watch = [path.resolve(__dirname, 'playground/mocks')];
const env = { MOCK_SERVER_PORT, DEV_SERVER_PORT };
const env = { MOCK_SERVER_PORT, DEV_SERVER_PORT, BASE_URL: require(WIDGET_RC_JS).baseUrl };
nodemon({ script, watch, env, delay: 50 })
.on('crash', console.error);
return middlewares;
Expand Down

0 comments on commit 59284e9

Please sign in to comment.