Skip to content

Commit 9e0bd9b

Browse files
author
Ives van Hoorne
committed
Merge branch 'master' into playground
2 parents 052292e + 92ecaff commit 9e0bd9b

File tree

26 files changed

+528
-672
lines changed

26 files changed

+528
-672
lines changed

.circleci/config.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@ jobs:
6969
name: Test Integrations
7070
command: |
7171
sleep 6
72-
yarn test:integrations
72+
yarn test:integrations --ci --testResultsProcessor="jest-junit"
73+
environment:
74+
JEST_JUNIT_OUTPUT: "/tmp/test-results/js-test-results.xml"
75+
- store_test_results:
76+
path: /tmp/test-results
7377
- store_artifacts:
7478
path: packages/app/integration-tests/tests/__image_snapshots__/__diff_output__
7579
destination: image_snapshot_diff
@@ -83,7 +87,9 @@ jobs:
8387
key: v2-repo-{{ .Environment.CIRCLE_SHA1 }}
8488
- run:
8589
name: Test
86-
command: yarn test
90+
command: yarn test --ci --testResultsProcessor="jest-junit"
91+
environment:
92+
JEST_JUNIT_OUTPUT: "reports/junit/js-test-results.xml"
8793

8894
lint:
8995
docker:

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"start:dev_api":
1515
"lerna run start --parallel --ignore app & lerna run start:dev_api --scope app --stream",
1616
"test": "lerna run test",
17-
"test:integrations": "lerna run test:integrations --scope app --stream",
17+
"test:integrations": "lerna exec --scope app --stream -- yarn test:integrations",
1818
"lint": "lerna run lint",
1919
"add-contributor": "all-contributors add",
2020
"generate": "all-contributors generate",

packages/app/config/webpack.common.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ module.exports = {
2424
require.resolve('./polyfills'),
2525
path.join(paths.sandboxSrc, 'index.js'),
2626
],
27+
'sandbox-startup': path.join(paths.sandboxSrc, 'startup.js'),
2728
}
2829
: {
2930
app: [
@@ -34,6 +35,7 @@ module.exports = {
3435
require.resolve('./polyfills'),
3536
path.join(paths.sandboxSrc, 'index.js'),
3637
],
38+
'sandbox-startup': path.join(paths.sandboxSrc, 'startup.js'),
3739
embed: [
3840
require.resolve('./polyfills'),
3941
path.join(paths.embedSrc, 'index.js'),
@@ -168,7 +170,7 @@ module.exports = {
168170
}),
169171
new HtmlWebpackPlugin({
170172
inject: true,
171-
chunks: ['common-sandbox', 'sandbox'],
173+
chunks: ['sandbox-startup', 'common-sandbox', 'sandbox'],
172174
filename: 'frame.html',
173175
template: paths.sandboxHtml,
174176
minify: __PROD__ && {

packages/app/integration-tests/tests/sandboxes.test.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,27 @@ const SANDBOXES = [
1111
'vVoQVk78',
1212
'github/faceyspacey/redux-first-router-codesandbox/tree/master',
1313
'mZRjw05yp',
14-
'pk1qjqpw67',
14+
1515
'o29j95wx9',
1616
'k3q1zjjml5',
1717
'github/reactjs/redux/tree/master/examples/real-world',
1818
'github/CompuIves/codesandbox-presentation',
1919
'lp5rjr0z4z',
2020
'nOymMxyY',
2121
];
22-
23-
SANDBOXES.forEach(sandbox => {
24-
const id = sandbox.id || sandbox;
25-
const threshold = sandbox.threshold || 0.01;
22+
describe('sandboxes', () => {
2623
let browser = puppeteer.launch({
2724
args: ['--no-sandbox', '--disable-setuid-sandbox'],
2825
});
26+
afterAll(() => {
27+
browser.close();
28+
});
2929

30-
describe('sandboxes', () => {
31-
afterAll(() => {
32-
browser.close();
33-
});
30+
SANDBOXES.forEach(sandbox => {
31+
const id = sandbox.id || sandbox;
32+
const threshold = sandbox.threshold || 0.01;
3433

35-
it.concurrent(
34+
it(
3635
`loads the sandbox with id '${id}'`,
3736
async () => {
3837
browser = await browser;
@@ -51,8 +50,10 @@ SANDBOXES.forEach(sandbox => {
5150
},
5251
customSnapshotIdentifier: id.split('/').join('-'),
5352
});
53+
54+
await page.close();
5455
},
55-
1000 * 60 * 10 // 10 minutes for all tests in total
56+
1000 * 60 * 1
5657
);
5758
});
5859
});

packages/app/package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"babel-macros": "^1.0.2",
2525
"babel-plugin-codegen": "^1.2.0",
2626
"babel-plugin-lodash": "^3.2.11",
27-
"babel-plugin-styled-components": "^1.1.7",
27+
"babel-plugin-styled-components": "^1.3.0",
2828
"babel-plugin-syntax-dynamic-import": "^6.18.0",
2929
"babel-plugin-transform-class-properties": "^6.24.1",
3030
"babel-plugin-transform-object-rest-spread": "^6.23.0",
@@ -59,6 +59,7 @@
5959
"husky": "^0.14.3",
6060
"jest": "^21.2.1",
6161
"jest-image-snapshot": "^1.0.1",
62+
"jest-junit": "^3.4.1",
6263
"jest-styled-components": "^4.9.0",
6364
"json-loader": "0.5.4",
6465
"object-assign": "^4.1.1",
@@ -159,21 +160,22 @@
159160
"react-redux": "^5.0.5",
160161
"react-router-dom": "^4.2.2",
161162
"react-router-redux": "next",
163+
"react-show": "^1.1.2",
162164
"react-split-pane": "^0.1.63",
163165
"react-stripe-elements": "^1.2.0",
164166
"react-tippy": "^0.14.0",
165167
"redbox-react": "^1.4.3",
166168
"redux": "^3.7.1",
167169
"reselect": "^3.0.1",
170+
"script-ext-html-webpack-plugin": "^1.8.8",
168171
"shelljs": "^0.7.8",
169172
"store": "^2.0.12",
170-
"styled-components": "^2.1.1",
173+
"styled-components": "^2.3.2",
171174
"svg-react-loader": "^0.4.4",
172175
"tern": "^0.21.0",
173176
"vue": "^2.5.2",
174177
"vue-template-compiler": "^2.5.2",
175-
"vue-template-es2015-compiler": "^1.6.0",
176-
"react-show": "^1.1.2"
178+
"vue-template-es2015-compiler": "^1.6.0"
177179
},
178180
"jest": {
179181
"roots": [

packages/app/src/app/components/sandbox/Preview/index.js

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ import { debounce } from 'lodash';
88
import type { Module, Sandbox, Preferences, Directory } from 'common/types';
99

1010
import { frameUrl } from 'common/utils/url-generator';
11-
import { findMainModule } from 'app/store/entities/sandboxes/modules/selectors';
11+
import { getModulePath } from 'app/store/entities/sandboxes/modules/selectors';
1212
import sandboxActionCreators from 'app/store/entities/sandboxes/actions';
13+
1314
import shouldUpdate from './utils/should-update';
1415

1516
import DevTools from './DevTools';
@@ -127,6 +128,12 @@ export default class Preview extends React.PureComponent<Props, State> {
127128
return;
128129
}
129130

131+
if (prevProps.dependencies !== this.props.dependencies) {
132+
// Changed dependencies
133+
this.executeCodeImmediately();
134+
return;
135+
}
136+
130137
if (prevProps.module.id !== this.props.module.id) {
131138
if (prevProps.isInProjectView && this.props.isInProjectView) {
132139
// If user only navigated while watching project
@@ -253,15 +260,14 @@ export default class Preview extends React.PureComponent<Props, State> {
253260
getRenderedModule = () => {
254261
const { modules, module, directories, entry, isInProjectView } = this.props;
255262
return isInProjectView
256-
? findMainModule(modules, directories, entry)
257-
: module;
263+
? '/' + entry
264+
: getModulePath(modules, directories, module.id);
258265
};
259266

260267
executeCodeImmediately = (initialRender: boolean = false) => {
261268
const {
262269
modules,
263270
directories,
264-
module,
265271
externalResources,
266272
preferences,
267273
dependencies,
@@ -286,18 +292,22 @@ export default class Preview extends React.PureComponent<Props, State> {
286292
this.evaluateInSandbox(`history.pushState({}, null, '/')`);
287293
}
288294

295+
// We convert the modules to a format the manager understands
296+
const normalizedModules = modules.map(m => ({
297+
path: getModulePath(modules, directories, m.id),
298+
code: m.code,
299+
}));
300+
289301
this.sendMessage({
290302
type: 'compile',
291-
module: renderedModule,
292-
changedModule: module,
303+
version: 2,
304+
entry: renderedModule,
293305
dependencies,
294-
modules,
295-
directories,
306+
modules: normalizedModules,
296307
sandboxId,
297308
externalResources,
298309
template,
299310
hasActions: !!runActionFromPreview,
300-
isModuleView: !isInProjectView,
301311
});
302312
}
303313
};

packages/app/src/app/index.html

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,27 @@
2424
<link rel="manifest" href="/manifest.json">
2525
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700|Source+Code+Pro:500" rel="stylesheet">
2626
<title>CodeSandbox</title>
27+
28+
<!-- AMD Loader for Monaco -->
29+
<link data-name="vs/editor/editor.main" rel="stylesheet" href="/public/vs/editor/editor.main.css">
30+
<script src="/public/vs/loader.js"></script>
31+
<script>
32+
window.require.config({
33+
url: '/public/vs/loader.js',
34+
paths: {
35+
vs: '/public/vs',
36+
},
37+
});
38+
</script>
39+
<script src="/public/vs/editor/editor.main.nls.js"></script>
40+
<script src="/public/vs/editor/editor.main.js"></script>
41+
2742
<!-- Google Tag Manager -->
2843
<script>
2944
(function (w, d, s, l, i) {
3045
w[l] = w[l] || []; w[l].push({
3146
'gtm.start':
32-
new Date().getTime(), event: 'gtm.js'
47+
new Date().getTime(), event: 'gtm.js'
3348
}); var f = d.getElementsByTagName(s)[0],
3449
j = d.createElement(s), dl = l != 'dataLayer' ? '&l=' + l : ''; j.async = true; j.src =
3550
'https://www.googletagmanager.com/gtm.js?id=' + i + dl; f.parentNode.insertBefore(j, f);
@@ -38,10 +53,8 @@
3853
<!-- End Google Tag Manager -->
3954
<script src="https://cdn.ravenjs.com/3.17.0/raven.min.js" crossorigin="anonymous"></script>
4055
<!-- <script async src="//cdn.headwayapp.co/widget.js"></script> -->
41-
<script async src="https://js.stripe.com/v3/"></script>
4256

43-
<!-- AMD Loader for Monaco -->
44-
<script src="/public/vs/loader.js"></script>
57+
<script async rel="prefetch" src="https://js.stripe.com/v3/"></script>
4558
</head>
4659

4760
<body style="margin: 0; padding: 0;">

packages/app/src/app/pages/Sandbox/Editor/Workspace/Dependencies/SearchDependencies.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,12 @@ export default class SearchDependencies extends React.PureComponent {
103103
hitToVersionMap = new Map();
104104

105105
handleSelect = hit => {
106-
const version = this.hitToVersionMap.get(hit);
106+
let version = this.hitToVersionMap.get(hit);
107+
108+
if (!version && hit.tags) {
109+
version = hit.tags.latest;
110+
}
111+
107112
this.props.onConfirm(hit.name, version);
108113
};
109114

packages/app/src/app/store/entities/sandboxes/utils/create-zip/create-react-app-typescript/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export default function createZip(
8787
'@types/node': '^8.0.28',
8888
},
8989
{
90-
'react-scripts-ts': '2.6.0',
90+
'react-scripts-ts': '2.8.0',
9191
},
9292
{
9393
start: 'react-scripts-ts start',

packages/app/src/embed/components/__snapshots__/File.test.js.snap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ exports[`File renders 1`] = `
4747
display: inline-block;
4848
-webkit-font-smoothing: antialiased;
4949
vertical-align: top;
50+
-webkit-flex-shrink: 0;
5051
-ms-flex-negative: 0;
5152
flex-shrink: 0;
5253
}
@@ -151,6 +152,7 @@ exports[`File renders alternative 1`] = `
151152
display: inline-block;
152153
-webkit-font-smoothing: antialiased;
153154
vertical-align: top;
155+
-webkit-flex-shrink: 0;
154156
-ms-flex-negative: 0;
155157
flex-shrink: 0;
156158
}
@@ -252,6 +254,7 @@ exports[`File renders as active 1`] = `
252254
display: inline-block;
253255
-webkit-font-smoothing: antialiased;
254256
vertical-align: top;
257+
-webkit-flex-shrink: 0;
255258
-ms-flex-negative: 0;
256259
flex-shrink: 0;
257260
}
@@ -356,6 +359,7 @@ exports[`File renders directory 1`] = `
356359
display: inline-block;
357360
-webkit-font-smoothing: antialiased;
358361
vertical-align: top;
362+
-webkit-flex-shrink: 0;
359363
-ms-flex-negative: 0;
360364
flex-shrink: 0;
361365
}

0 commit comments

Comments
 (0)