support test coverage of solid app

This commit is contained in:
Nacho Codoñer
2025-08-20 11:38:28 +02:00
parent b05645be1f
commit 324d8b8aa8
21 changed files with 6773 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
node_modules/
# Meteor-Rspack build context directories
_build
public/_build-bundles
public/_build-assets
private/_build-assets

View File

@@ -0,0 +1 @@
local

View File

@@ -0,0 +1,7 @@
# This file contains a token that is unique to your project.
# Check it into your repository along with the rest of this directory.
# It can be used for purposes such as:
# - ensuring you don't accidentally deploy one app on top of another
# - providing package authors with aggregated statistics
l9l5u78nay5.axumzntivb1

View File

@@ -0,0 +1,22 @@
# Meteor packages used by this project, one per line.
# Check this file (and the other files in this directory) into your repository.
#
# 'meteor add' and 'meteor remove' will edit this file for you,
# but you can also edit it by hand.
meteor-base # Packages every Meteor app needs to have
mobile-experience # Packages for a great mobile UX
mongo # The database Meteor supports right now
reactive-var # Reactive variable for tracker
standard-minifier-css # CSS minifier run for production mode
standard-minifier-js # JS minifier run for production mode
es5-shim # ECMAScript 5 compatibility for older browsers
ecmascript # Enable ECMAScript2015+ syntax in app code
typescript # Enable TypeScript syntax in .ts and .tsx modules
shell-server # Server-side component of the `meteor shell` command
hot-module-replacement # Update client in development without reloading the page
static-html # Define static page content in .html files
rspack

View File

@@ -0,0 +1,2 @@
server
browser

View File

@@ -0,0 +1 @@
none

View File

@@ -0,0 +1,68 @@
allow-deny@2.1.0
autoupdate@2.0.1
babel-compiler@7.12.1
babel-runtime@1.5.2
base64@1.0.13
binary-heap@1.0.12
boilerplate-generator@2.0.1
caching-compiler@2.0.1
callback-hook@1.6.1
check@1.4.4
core-runtime@1.0.0
ddp@1.4.2
ddp-client@3.1.1
ddp-common@1.4.4
ddp-server@3.1.2
diff-sequence@1.1.3
dynamic-import@0.7.4
ecmascript@0.16.12
ecmascript-runtime@0.8.3
ecmascript-runtime-client@0.12.3
ecmascript-runtime-server@0.11.1
ejson@1.1.5
es5-shim@4.8.1
facts-base@1.0.2
fetch@0.1.6
geojson-utils@1.0.12
hot-code-push@1.0.5
hot-module-replacement@0.5.4
id-map@1.2.0
inter-process-messaging@0.1.2
launch-screen@2.0.1
logging@1.3.6
meteor@2.1.1
meteor-base@1.5.2
minifier-css@2.0.1
minifier-js@3.0.3
minimongo@2.0.3
mobile-experience@1.1.2
mobile-status-bar@1.1.1
modern-browsers@0.2.3
modules@0.20.3
modules-runtime@0.13.2
modules-runtime-hot@0.14.3
mongo@2.1.3
mongo-decimal@0.2.0
mongo-dev-server@1.1.1
mongo-id@1.0.9
npm-mongo@6.16.0
ordered-dict@1.2.0
promise@1.0.0
random@1.2.2
react-fast-refresh@0.2.9
reactive-var@1.0.13
reload@1.3.2
retry@1.1.1
routepolicy@1.1.2
rspack@1.0.0-beta340.0
shell-server@0.6.1
socket-stream-client@0.6.1
standard-minifier-css@1.9.3
standard-minifier-js@3.1.1
static-html@1.4.0
static-html-tools@1.0.0
tools-core@1.0.0-beta340.0
tracker@1.3.4
typescript@5.6.5
webapp@2.0.7
webapp-hashing@1.1.2

View File

@@ -0,0 +1,10 @@
<head>
<title>solid</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
</body>

View File

@@ -0,0 +1 @@
import '../imports/ui/main';

View File

@@ -0,0 +1,4 @@
import { Mongo } from 'meteor/mongo';
export const LinksCollection = new Mongo.Collection('links');

View File

@@ -0,0 +1,12 @@
import { Hello } from "./Hello";
import { Info } from "./Info";
export const App = () => (
<div>
<h1>Welcome to Meteor!</h1>
<Hello/>
<Info/>
</div>
);

View File

@@ -0,0 +1,16 @@
import { createSignal } from "solid-js";
export const Hello = () => {
const [counter, setCounter] = createSignal(0);
const increment = () => {
setCounter(counter() + 1);
};
return (
<div>
<button onClick={increment}>Click Me</button>
<p>You've pressed the button {counter()} times.</p>
</div>
);
}

View File

@@ -0,0 +1,37 @@
import { LinksCollection } from "../api/links";
import { createSignal, For, Show } from "solid-js";
import { Tracker } from "meteor/tracker";
import { Meteor } from "meteor/meteor";
export const Info = () => {
const subscription = Meteor.subscribe("links");
const [isReady, setIsReady] = createSignal(subscription.ready());
const [links, setLinks] = createSignal([]);
Tracker.autorun(async () => {
setIsReady(subscription.ready());
setLinks(await LinksCollection.find().fetchAsync());
});
return (
<Show
when={isReady()}
fallback={<div>Loading...</div>}
>
<div>
<h2>Learn Meteor!</h2>
<ul>
<For each={links()}>
{(link) => (
<li>
<a href={link.url} target="_blank">
{link.title}
</a>
</li>
)}
</For>
</ul>
</div>
</Show>
);
};

View File

@@ -0,0 +1,4 @@
body {
padding: 10px;
font-family: sans-serif;
}

View File

@@ -0,0 +1,9 @@
/* @refresh reload */
import { render } from 'solid-js/web';
import { App } from './App';
import { Meteor } from "meteor/meteor";
import './main.css';
Meteor.startup(() => {
render(() => <App/>, document.getElementById('root'));
})

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,34 @@
{
"name": "solid",
"private": true,
"scripts": {
"start": "meteor run",
"test": "meteor test --once --driver-package meteortesting:mocha",
"test-app": "TEST_WATCH=1 meteor test --full-app --driver-package meteortesting:mocha",
"visualize": "meteor --production --extra-packages bundle-visualizer"
},
"dependencies": {
"@babel/runtime": "^7.23.9",
"@swc/helpers": "^0.5.17",
"meteor-node-stubs": "^1.2.12",
"picocolors": "^1.1.1"
},
"meteor": {
"mainModule": {
"client": "client/main.js",
"server": "server/main.js"
},
"testModule": "tests/main.js",
"modern": true
},
"devDependencies": {
"@meteorjs/rspack": "^0.0.29",
"@rspack/cli": "^1.4.8",
"@rspack/core": "^1.4.8",
"babel-loader": "10.0.0",
"babel-preset-solid": "^1.8.15",
"playwright": "^1.54.2",
"solid-js": "^1.9.4",
"solid-refresh": "0.7.5"
}
}

View File

@@ -0,0 +1,38 @@
import { defineConfig } from '@meteorjs/rspack';
/**
* Rspack configuration for Meteor projects.
*
* Provides typed flags on the `Meteor` object, such as:
* - `Meteor.isClient` / `Meteor.isServer`
* - `Meteor.isDevelopment` / `Meteor.isProduction`
* - …and other flags available
*
* Use these flags to adjust your build settings based on environment.
*/
export default defineConfig(Meteor => {
return {
...Meteor.isClient && {
module: {
rules: [
{
test: /\.jsx$/,
use: [
{
loader: 'babel-loader',
options: {
presets: [['solid']],
plugins: ['solid-refresh/babel'],
},
},
],
},
{
test: /\.svg$/,
type: 'asset/resource',
},
],
},
}
};
});

View File

@@ -0,0 +1,37 @@
import { Meteor } from 'meteor/meteor';
import { LinksCollection } from '/imports/api/links';
async function insertLink({ title, url }) {
await LinksCollection.insertAsync({ title, url, createdAt: new Date() });
}
Meteor.startup(async () => {
// If the Links collection is empty, add some data.
if (await LinksCollection.find().countAsync() === 0) {
await insertLink({
title: 'Do the Tutorial',
url: 'https://www.solidjs.com/tutorial/introduction_basics',
});
await insertLink({
title: 'Follow the Guide',
url: 'https://guide.meteor.com',
});
await insertLink({
title: 'Read the Docs',
url: 'https://docs.meteor.com',
});
await insertLink({
title: 'Discussions',
url: 'https://forums.meteor.com',
});
}
// We publish the entire Links collection to all clients.
// In order to be fetched in real-time to the clients
Meteor.publish('links', function () {
return LinksCollection.find();
});
});

View File

@@ -0,0 +1,20 @@
import assert from "assert";
describe("solid", function () {
it("package.json has correct name", async function () {
const { name } = await import("../package.json");
assert.strictEqual(name, "solid");
});
if (Meteor.isClient) {
it("client is not server", function () {
assert.strictEqual(Meteor.isServer, false);
});
}
if (Meteor.isServer) {
it("server is not client", function () {
assert.strictEqual(Meteor.isClient, false);
});
}
});

View File

@@ -0,0 +1,26 @@
import {
waitForMeteorOutput,
} from "./helpers";
import { testMeteorRspackBundler } from './test-helpers';
describe('Solid App Bundling /', () => {
describe('Meteor+Rspack Bundler /', testMeteorRspackBundler({
appName: 'solid',
port: 3122,
filePaths: {
client: 'client/main.js',
server: 'server/main.js',
test: 'tests/main.js'
},
customAssertions: {
afterRunRebuildClient: async ({ allConsoleLogs }) => {
// Check for HMR output as enabled by default
await waitForMeteorOutput(allConsoleLogs, /.*HMR.*Updated modules:.*/);
},
afterRunProductionRebuildClient: async ({ allConsoleLogs }) => {
// Check for HMR to not be enabled in production-like mode
await waitForMeteorOutput(allConsoleLogs, /.*HMR.*Updated modules:*/, { negate: true });
},
}
}));
});