Skip to content

Commit

Permalink
Merge branch 'allow-window-property-for-sharding' of github.com:atlas…
Browse files Browse the repository at this point in the history
…sian-labs/atlaspack into allow-window-property-for-sharding
  • Loading branch information
benjervis committed Dec 15, 2024
2 parents c70c904 + 64c21f0 commit 7e5de5f
Show file tree
Hide file tree
Showing 10 changed files with 171 additions and 70 deletions.
6 changes: 5 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ const paths = {
'!**/dev-prelude.js',
...IGNORED_PACKAGES,
],
packageOther: ['packages/*/*/src/**/dev-prelude.js'],
packageOther: [
'packages/*/*/src/**/dev-prelude.js',
// This has to have some glob syntax so that vinyl.base will be right
'packages/{runtimes,}/js/src/helpers/*.ts',
],
packages: 'packages/',
};

Expand Down
5 changes: 5 additions & 0 deletions packages/core/integration-tests/test/rust.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @flow
import assert from 'assert';
import path from 'path';
import {
Expand Down Expand Up @@ -48,12 +49,14 @@ describe.skip('rust', function () {

// not minified
assert(
// $FlowFixMe old api, test is skipped
(await outputFS.stat(Array.from(b.childBundles)[0].name)).size > 500,
);
});

it('should generate a wasm file from a rust file with rustc with --target=node', async function () {
this.timeout(500000);
// $FlowFixMe old api, test is skipped
let b = await bundle(path.join(__dirname, '/integration/rust/index.js'), {
target: 'node',
});
Expand Down Expand Up @@ -84,13 +87,15 @@ describe.skip('rust', function () {

// not minified
assert(
// $FlowFixMe old api, test is skipped
(await outputFS.stat(Array.from(b.childBundles)[0].name)).size > 500,
);
});

it('should support rust files with dependencies via rustc', async function () {
this.timeout(500000);
let b = bundler(path.join(__dirname, '/integration/rust-deps/index.js'));
// $FlowFixMe old api, test is skipped
let bundle = await b.bundle();

await assertBundleTree(bundle, {
Expand Down
25 changes: 16 additions & 9 deletions packages/core/integration-tests/test/schema-jsonld.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @flow
import {
assertBundles,
bundle,
Expand All @@ -14,7 +15,9 @@ describe.v2('jsonld', function () {
let b = await bundle(
path.join(__dirname, '/integration/schema-jsonld/index.html'),
{
publicURL: 'https://place.holder/',
defaultTargetOptions: {
publicUrl: 'https://place.holder/',
},
},
);

Expand Down Expand Up @@ -47,25 +50,29 @@ describe.v2('jsonld', function () {
);
let contentBetweenScriptTag = new RegExp(
/<\s*script \s*type="application\/ld\+json"\s*>(.*)<\/\s*script\s*>/gm,
).exec(file)[1];
).exec(file)?.[1];

let jsonldData = assertValidJsonObject(contentBetweenScriptTag);
match(jsonldData.logo.url, /logo\.[a-f0-9]+\.png/);
match(jsonldData.image[0], /image\.[a-f0-9]+\.jpeg/);
match(jsonldData.image[1], /image\.[a-f0-9]+\.jpeg/);
match(jsonldData?.logo.url, /logo\.[a-f0-9]+\.png/);
match(jsonldData?.image[0], /image\.[a-f0-9]+\.jpeg/);
match(jsonldData?.image[1], /image\.[a-f0-9]+\.jpeg/);
});
});

function match(test, pattern) {
function match(test?: string, pattern: RegExp | string) {
if (!test) return assert.fail();
let success = new RegExp(pattern).test(test);
if (success) {
assert.ok(`'${test}' matched the given pattern of '${pattern}'`);
assert.ok(`'${test}' matched the given pattern of '${pattern.toString()}'`);
return;
}
assert.fail(`'${test}' did not match the given pattern of '${pattern}'`);
assert.fail(
`'${test}' did not match the given pattern of '${pattern.toString()}'`,
);
}

function assertValidJsonObject(dataAsString) {
function assertValidJsonObject(dataAsString?: string) {
if (!dataAsString) return assert.fail();
try {
let data = JSON.parse(dataAsString);
assert.ok('input string is a valid json object');
Expand Down
95 changes: 55 additions & 40 deletions packages/core/integration-tests/test/svg.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @flow
import assert from 'assert';
import {
assertBundles,
Expand Down Expand Up @@ -52,51 +53,59 @@ describe('svg', function () {
},
]);

let file = await outputFS.readFile(
b.getBundles().find((b) => b.type === 'svg').filePath,
'utf-8',
);
let svgBundle = b.getBundles().find((b) => b.type === 'svg');
if (!svgBundle) return assert.fail();

let file = await outputFS.readFile(svgBundle.filePath, 'utf-8');
assert(file.includes('<a href="/other1.html">'));
assert(file.includes('<use href="#circle"'));

let squareBundle = b.getBundles().find((b) => b.name.startsWith('square'));
if (!squareBundle) return assert.fail();

assert(
file.includes(
`<use xlink:href="/${path.basename(
b.getBundles().find((b) => b.name.startsWith('square')).filePath,
)}#square"`,
`<use xlink:href="/${path.basename(squareBundle.filePath)}#square"`,
),
);

let gradientBundle = b
.getBundles()
.find((b) => b.name.startsWith('gradient'));
if (!gradientBundle) return assert.fail();

assert(
file.includes(
`fill="url('/${path.basename(
b.getBundles().find((b) => b.name.startsWith('gradient')).filePath,
)}#myGradient')"`,
`fill="url('/${path.basename(gradientBundle.filePath)}#myGradient')"`,
),
);

let scriptBundle = b
.getBundles()
.find((b) => b.type === 'js' && b.env.sourceType === 'script');
if (!scriptBundle) return assert.fail();

assert(
file.includes(
`<script xlink:href="/${path.basename(
b
.getBundles()
.find((b) => b.type === 'js' && b.env.sourceType === 'script')
.filePath,
)}"`,
`<script xlink:href="/${path.basename(scriptBundle.filePath)}"`,
),
);

let moduleBundle = b
.getBundles()
.find((b) => b.type === 'js' && b.env.sourceType === 'module');
if (!moduleBundle) return assert.fail();

assert(
file.includes(
`<script href="/${path.basename(
b
.getBundles()
.find((b) => b.type === 'js' && b.env.sourceType === 'module')
.filePath,
)}"`,
),
file.includes(`<script href="/${path.basename(moduleBundle.filePath)}"`),
);

let cssBundle = b.getBundles().find((b) => b.type === 'css');
if (!cssBundle) return assert.fail();

assert(
file.includes(
`<?xml-stylesheet href="/${path.basename(
b.getBundles().find((b) => b.type === 'css').filePath,
)}"?>`,
`<?xml-stylesheet href="/${path.basename(cssBundle.filePath)}"?>`,
),
);
});
Expand All @@ -108,10 +117,10 @@ describe('svg', function () {
},
});

let file = await outputFS.readFile(
b.getBundles().find((b) => b.type === 'svg').filePath,
'utf-8',
);
let svgBundle = b.getBundles().find((b) => b.type === 'svg');
if (!svgBundle) return assert.fail();

let file = await outputFS.readFile(svgBundle.filePath, 'utf-8');
assert(!file.includes('comment'));
});

Expand All @@ -125,10 +134,10 @@ describe('svg', function () {
},
);

let file = await outputFS.readFile(
b.getBundles().find((b) => b.type === 'svg').filePath,
'utf-8',
);
let svgBundle = b.getBundles().find((b) => b.type === 'svg');
if (!svgBundle) return assert.fail();

let file = await outputFS.readFile(svgBundle.filePath, 'utf-8');
assert(!file.includes('inkscape'));
assert(file.includes('comment'));
});
Expand All @@ -155,10 +164,10 @@ describe('svg', function () {
},
]);

let file = await outputFS.readFile(
b.getBundles().find((b) => b.type === 'svg').filePath,
'utf-8',
);
let svgBundle = b.getBundles().find((b) => b.type === 'svg');
if (!svgBundle) return assert.fail();

let file = await outputFS.readFile(svgBundle.filePath, 'utf-8');

assert(file.includes('<?xml-stylesheet'));
assert(file.includes('<?xml-not-a-stylesheet'));
Expand Down Expand Up @@ -197,10 +206,16 @@ describe('svg', function () {

assert(!svg.includes('@import'));
assert(svg.includes(':root {\n fill: red;\n}'));

let gradientBundle = b
.getBundles()
.find((b) => b.name.startsWith('gradient'));
if (!gradientBundle) return assert.fail();

assert(
svg.includes(
`"fill: url(&quot;${path.basename(
b.getBundles().find((b) => b.name.startsWith('gradient')).filePath,
gradientBundle.filePath,
)}#myGradient&quot;)`,
),
);
Expand Down
1 change: 1 addition & 0 deletions packages/core/integration-tests/test/ts-types.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @flow
import assert from 'assert';
import path from 'path';
import {
Expand Down
10 changes: 10 additions & 0 deletions packages/core/integration-tests/test/ts-validation.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @flow
import assert from 'assert';
import path from 'path';
import {
Expand Down Expand Up @@ -94,6 +95,7 @@ describe.v2('ts-validator', function () {
subscription = await b.watch();
let buildEvent = await getNextBuild(b);
assert.equal(buildEvent.type, 'buildFailure');
if (!buildEvent.diagnostics) return assert.fail();
assert.equal(buildEvent.diagnostics.length, 1);
assert.equal(
buildEvent.diagnostics[0].message,
Expand All @@ -106,6 +108,7 @@ describe.v2('ts-validator', function () {
);
buildEvent = await getNextBuild(b);
assert.equal(buildEvent.type, 'buildSuccess');
if (!buildEvent.bundleGraph) return assert.fail();
let output = await run(buildEvent.bundleGraph);
assert.equal(output.message, 'The type error is fixed!');

Expand All @@ -115,6 +118,7 @@ describe.v2('ts-validator', function () {
);
buildEvent = await getNextBuild(b);
assert.equal(buildEvent.type, 'buildFailure');
if (!buildEvent.diagnostics) return assert.fail();
assert.equal(buildEvent.diagnostics.length, 1);
assert.equal(
buildEvent.diagnostics[0].message,
Expand Down Expand Up @@ -146,6 +150,7 @@ describe.v2('ts-validator', function () {

let buildEvent = await getNextBuild(b);
assert.equal(buildEvent.type, 'buildSuccess');
if (!buildEvent.bundleGraph) return assert.fail();
let output = await run(buildEvent.bundleGraph);
assert.equal(output.output, 'My Message!');

Expand All @@ -162,6 +167,7 @@ describe.v2('ts-validator', function () {

buildEvent = await getNextBuild(b);
assert.equal(buildEvent.type, 'buildSuccess');
if (!buildEvent.bundleGraph) return assert.fail();
output = await run(buildEvent.bundleGraph);
assert.equal(output.output, 123456);
});
Expand Down Expand Up @@ -190,6 +196,7 @@ describe.v2('ts-validator', function () {

let buildEvent = await getNextBuild(b);
assert.equal(buildEvent.type, 'buildFailure');
if (!buildEvent.diagnostics) return assert.fail();
assert.equal(buildEvent.diagnostics.length, 2);
assert.equal(
buildEvent.diagnostics[1].message,
Expand All @@ -209,6 +216,7 @@ describe.v2('ts-validator', function () {

buildEvent = await getNextBuild(b);
assert.equal(buildEvent.type, 'buildFailure');
if (!buildEvent.diagnostics) return assert.fail();
assert.equal(buildEvent.diagnostics.length, 1);
assert.equal(
buildEvent.diagnostics[0].message,
Expand Down Expand Up @@ -240,6 +248,7 @@ describe.v2('ts-validator', function () {

let buildEvent = await getNextBuild(b);
assert.equal(buildEvent.type, 'buildSuccess');
if (!buildEvent.bundleGraph) return assert.fail();
let output = await run(buildEvent.bundleGraph);
assert.equal(output.output, 'My Message!');

Expand All @@ -250,6 +259,7 @@ describe.v2('ts-validator', function () {

buildEvent = await getNextBuild(b);
assert.equal(buildEvent.type, 'buildFailure');
if (!buildEvent.diagnostics) return assert.fail();
assert.equal(buildEvent.diagnostics.length, 1);
assert.equal(
buildEvent.diagnostics[0].message,
Expand Down
Loading

0 comments on commit 7e5de5f

Please sign in to comment.