Skip to content

Commit b098276

Browse files
committed
fixing standalone tests
1 parent 0aea1af commit b098276

4 files changed

Lines changed: 44 additions & 21 deletions

File tree

test.config.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import createEsmUtils from 'esm-utils';
44
const { __dirname } = createEsmUtils(import.meta);
55

66
export default {
7-
entry: './tests/integration/test-app.js',
7+
entry: {
8+
test: './tests/integration/test-app.js',
9+
'create-parser': './src/slang-utils/create-parser.js'
10+
},
811
mode: 'production',
912
bail: true,
1013

@@ -13,14 +16,25 @@ export default {
1316

1417
externals: { 'node:fs/promises': 'import node:fs/promises' },
1518

16-
experiments: {
17-
asyncWebAssembly: true,
18-
topLevelAwait: true,
19-
outputModule: true
19+
resolve: {
20+
extensions: ['.ts', '.js'],
21+
extensionAlias: { '.js': ['.js', '.ts'] }
22+
},
23+
24+
module: {
25+
rules: [
26+
{
27+
test: /\.ts$/,
28+
use: 'ts-loader',
29+
exclude: /node_modules/
30+
}
31+
]
2032
},
2133

34+
experiments: { outputModule: true },
35+
2236
output: {
23-
filename: 'test.js',
37+
filename: '[name].js',
2438
path: path.resolve(__dirname, 'dist'),
2539
library: { type: 'module' }
2640
},

tests/config/get-create-parser.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
function getCreateParserInternal() {
2+
const entry = process.env.TEST_STANDALONE
3+
? "../../dist/create-parser.js"
4+
: "../../src/slang-utils/create-parser.js";
5+
6+
return import(entry).then((module) => module.createParser);
7+
}
8+
9+
let promise;
10+
function getCreateParser() {
11+
promise = promise ?? getCreateParserInternal();
12+
13+
return promise;
14+
}
15+
16+
export default getCreateParser;

tests/config/run-format-test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import path from "node:path";
33
import url from "node:url";
44
import createEsmUtils from "esm-utils";
55
import getPrettier from "./get-prettier.js";
6+
import getCreateParser from "./get-create-parser.js";
67
import getPlugins from "./get-plugins.js";
78
import compileContract from "./utils/compile-contract.js";
89
import consistentEndOfLine from "./utils/consistent-end-of-line.js";
910
import createSnapshot from "./utils/create-snapshot.js";
1011
import stringifyOptionsForTitle from "./utils/stringify-options-for-title.js";
1112
import visualizeEndOfLine from "./utils/visualize-end-of-line.js";
12-
import { createParser } from "../../src/slang-utils/create-parser.js";
1313

1414
const { __dirname } = createEsmUtils(import.meta);
1515

@@ -327,6 +327,7 @@ async function runTest({
327327
) {
328328
// Compare with ANTLR's format
329329
const prettier = await getPrettier();
330+
const createParser = await getCreateParser();
330331
const { formatted: antlrOutput } = await prettier.formatWithCursor(code, {
331332
...formatOptions,
332333
// Since Slang forces us to decide on a compiler version, we need to do the

webpack.config.js

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ import webpack from 'webpack';
44

55
const { __dirname } = createEsmUtils(import.meta);
66

7-
const globalObject = `
8-
typeof globalThis !== 'undefined' ? globalThis
7+
const globalObject = `typeof globalThis !== 'undefined' ? globalThis
98
: typeof global !== 'undefined' ? global
109
: typeof self !== 'undefined' ? self
11-
: this || {}
12-
`;
10+
: this || {}`;
1311

1412
// This is the production and development configuration.
1513
// It is focused on developer experience, fast rebuilds, and a minimal bundle.
@@ -29,10 +27,8 @@ export default (webpackEnv) => {
2927
// TODO: investigate a cleaner way to populate the global variable
3028
// prettierPlugins in a browser.
3129
new webpack.BannerPlugin({
32-
banner: `
33-
var root = ${globalObject};
34-
root["prettierPlugins"] = root["prettierPlugins"] || {}, root["prettierPlugins"]["solidity"] = __webpack_exports__default;
35-
`,
30+
banner: `var root = ${globalObject};
31+
root["prettierPlugins"] = root["prettierPlugins"] || {}, root["prettierPlugins"]["solidity"] = __webpack_exports__default;`,
3632
footer: true,
3733
raw: true
3834
})
@@ -46,12 +42,6 @@ root["prettierPlugins"] = root["prettierPlugins"] || {}, root["prettierPlugins"]
4642
extensionAlias: { '.js': ['.js', '.ts'] }
4743
},
4844

49-
experiments: {
50-
asyncWebAssembly: true,
51-
topLevelAwait: true,
52-
outputModule: true
53-
},
54-
5545
module: {
5646
rules: [
5747
{
@@ -62,6 +52,8 @@ root["prettierPlugins"] = root["prettierPlugins"] || {}, root["prettierPlugins"]
6252
]
6353
},
6454

55+
experiments: { outputModule: true },
56+
6557
optimization: { minimize: isEnvProduction },
6658
target: ['browserslist'],
6759
output: {

0 commit comments

Comments
 (0)