fix(core): update
This commit is contained in:
parent
af030ed013
commit
ad2866ae0b
@ -11,7 +11,7 @@
|
|||||||
"tstest": "./cli.js"
|
"tstest": "./cli.js"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(npm run cleanUp && npm run prepareTest && npm run tstest && npm run cleanUp)",
|
"test": "(npm run cleanUp && npm run prepareTest && npm run tstest)",
|
||||||
"prepareTest": "git clone https://gitlab.com/sandboxzone/sandbox-npmts.git .nogit/sandbox-npmts && cd .nogit/sandbox-npmts && npm install",
|
"prepareTest": "git clone https://gitlab.com/sandboxzone/sandbox-npmts.git .nogit/sandbox-npmts && cd .nogit/sandbox-npmts && npm install",
|
||||||
"tstest": "cd .nogit/sandbox-npmts && node ../../cli.ts.js test/ --web",
|
"tstest": "cd .nogit/sandbox-npmts && node ../../cli.ts.js test/ --web",
|
||||||
"cleanUp": "rm -rf .nogit/sandbox-npmts",
|
"cleanUp": "rm -rf .nogit/sandbox-npmts",
|
||||||
|
@ -35,11 +35,11 @@ export class TsTest {
|
|||||||
}
|
}
|
||||||
console.log('-'.repeat(48));
|
console.log('-'.repeat(48));
|
||||||
console.log(''); // force new line
|
console.log(''); // force new line
|
||||||
|
|
||||||
const tapCombinator = new TapCombinator(); // lets create the TapCombinator
|
const tapCombinator = new TapCombinator(); // lets create the TapCombinator
|
||||||
for (const fileNameArg of fileNamesToRun) {
|
for (const fileNameArg of fileNamesToRun) {
|
||||||
let tapParser: TapParser;
|
let tapParser: TapParser;
|
||||||
switch(true) {
|
switch (true) {
|
||||||
case fileNameArg.endsWith('.browser.ts'):
|
case fileNameArg.endsWith('.browser.ts'):
|
||||||
tapParser = await this.runInChrome(fileNameArg);
|
tapParser = await this.runInChrome(fileNameArg);
|
||||||
break;
|
break;
|
||||||
@ -75,48 +75,143 @@ export class TsTest {
|
|||||||
public async runInChrome(fileNameArg: string): Promise<TapParser> {
|
public async runInChrome(fileNameArg: string): Promise<TapParser> {
|
||||||
console.log(`${cs('=> ', 'blue')} Running ${cs(fileNameArg, 'orange')} in chromium runtime.`);
|
console.log(`${cs('=> ', 'blue')} Running ${cs(fileNameArg, 'orange')} in chromium runtime.`);
|
||||||
console.log(cs(`=`.repeat(16), 'cyan'));
|
console.log(cs(`=`.repeat(16), 'cyan'));
|
||||||
|
|
||||||
// lets get all our paths sorted
|
// lets get all our paths sorted
|
||||||
const tsbundleCacheDirPath = plugins.path.join(paths.cwd, './.nogit/tstest_cache');
|
const tsbundleCacheDirPath = plugins.path.join(paths.cwd, './.nogit/tstest_cache');
|
||||||
const bundleFileName = fileNameArg.replace('/', '__') + '.js';
|
const bundleFileName = fileNameArg.replace('/', '__') + '.js';
|
||||||
const bundleFilePath = plugins.path.join(tsbundleCacheDirPath, bundleFileName);
|
const bundleFilePath = plugins.path.join(tsbundleCacheDirPath, bundleFileName);
|
||||||
|
|
||||||
// lets bundle the test
|
// lets bundle the test
|
||||||
await plugins.smartfile.fs.ensureDir(tsbundleCacheDirPath);
|
await plugins.smartfile.fs.ensureDir(tsbundleCacheDirPath);
|
||||||
await this.tsbundleInstance.buildTest(fileNameArg, bundleFilePath, 'parcel');
|
await this.tsbundleInstance.buildTest(fileNameArg, bundleFilePath, 'parcel');
|
||||||
|
|
||||||
// lets create a server
|
// lets create a server
|
||||||
const server = new plugins.smartexpress.Server({
|
const server = new plugins.smartexpress.Server({
|
||||||
cors: true,
|
cors: true,
|
||||||
port: 3007
|
port: 3007,
|
||||||
});
|
});
|
||||||
server.addRoute('/test', new plugins.smartexpress.Handler('GET', async (req, res) => {
|
server.addRoute(
|
||||||
res.type('.html');
|
'/test',
|
||||||
res.write(`
|
new plugins.smartexpress.Handler('GET', async (req, res) => {
|
||||||
|
res.type('.html');
|
||||||
|
res.write(`
|
||||||
<html>
|
<html>
|
||||||
<head></head>
|
<head>
|
||||||
|
<script>
|
||||||
|
globalThis.testdom = true;
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
<body></body>
|
<body></body>
|
||||||
</html>
|
</html>
|
||||||
`);
|
`);
|
||||||
res.end();
|
res.end();
|
||||||
}));
|
})
|
||||||
|
);
|
||||||
server.addRoute('*', new plugins.smartexpress.HandlerStatic(tsbundleCacheDirPath));
|
server.addRoute('*', new plugins.smartexpress.HandlerStatic(tsbundleCacheDirPath));
|
||||||
await server.start();
|
await server.start();
|
||||||
|
|
||||||
// lets do the browser bit
|
// lets do the browser bit
|
||||||
await this.smartbrowserInstance.start();
|
await this.smartbrowserInstance.start();
|
||||||
const evaluation = await this.smartbrowserInstance.evaluateOnPage('http://localhost:3007/test', async () => {
|
const evaluation = await this.smartbrowserInstance.evaluateOnPage(
|
||||||
const logStore = 'hello';
|
`http://localhost:3007/test?bundleName=${bundleFileName}`,
|
||||||
const log = console.log.bind(console);
|
async () => {
|
||||||
console.log = (...args) => {
|
let logStore = 'Starting log capture\n';
|
||||||
log('My Console!!!');
|
// tslint:disable-next-line: max-classes-per-file
|
||||||
log(...args);
|
class Deferred<T> {
|
||||||
};
|
public promise: Promise<T>;
|
||||||
const script = document.createElement('script');
|
public resolve;
|
||||||
script.src = '/test__test.browser.ts.js';
|
public reject;
|
||||||
document.head.appendChild(script);
|
public status;
|
||||||
return logStore;
|
|
||||||
});
|
public startedAt: number;
|
||||||
|
public stoppedAt: number;
|
||||||
|
public get duration(): number {
|
||||||
|
if (this.stoppedAt) {
|
||||||
|
return this.stoppedAt - this.startedAt;
|
||||||
|
} else {
|
||||||
|
return Date.now() - this.startedAt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.promise = new Promise<T>((resolve, reject) => {
|
||||||
|
this.resolve = (valueArg: T | PromiseLike<T>) => {
|
||||||
|
this.status = 'fulfilled';
|
||||||
|
this.stoppedAt = Date.now();
|
||||||
|
resolve(valueArg);
|
||||||
|
};
|
||||||
|
this.reject = (reason: any) => {
|
||||||
|
this.status = 'rejected';
|
||||||
|
this.stoppedAt = Date.now();
|
||||||
|
reject(reason);
|
||||||
|
};
|
||||||
|
this.startedAt = Date.now();
|
||||||
|
this.status = 'pending';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const done = new Deferred();
|
||||||
|
const convertToText = (obj) => {
|
||||||
|
// create an array that will later be joined into a string.
|
||||||
|
const stringArray = [];
|
||||||
|
|
||||||
|
if (typeof obj === 'object' && obj.join === undefined) {
|
||||||
|
stringArray.push('{');
|
||||||
|
for (const prop of Object.keys(obj)) {
|
||||||
|
stringArray.push(prop, ': ', convertToText(obj[prop]), ',');
|
||||||
|
}
|
||||||
|
stringArray.push('}');
|
||||||
|
|
||||||
|
// is array
|
||||||
|
} else if (typeof obj === 'object' && !(obj.join === undefined)) {
|
||||||
|
stringArray.push('[');
|
||||||
|
for (const prop of Object.keys(obj)) {
|
||||||
|
stringArray.push(convertToText(obj[prop]), ',');
|
||||||
|
}
|
||||||
|
stringArray.push(']');
|
||||||
|
|
||||||
|
// is function
|
||||||
|
} else if (typeof obj === 'function') {
|
||||||
|
stringArray.push(obj.toString());
|
||||||
|
|
||||||
|
// all other values can be done with JSON.stringify
|
||||||
|
} else {
|
||||||
|
stringArray.push(JSON.stringify(obj));
|
||||||
|
}
|
||||||
|
|
||||||
|
return stringArray.join('');
|
||||||
|
};
|
||||||
|
const log = console.log.bind(console);
|
||||||
|
console.log = (...args) => {
|
||||||
|
args = args.map((argument) => {
|
||||||
|
return typeof argument !== 'string' ? convertToText(argument) : argument;
|
||||||
|
});
|
||||||
|
logStore += `${args}\n`;
|
||||||
|
log(...args);
|
||||||
|
};
|
||||||
|
const error = console.error;
|
||||||
|
console.error = (...args) => {
|
||||||
|
args = args.map((argument) => {
|
||||||
|
return typeof argument !== 'string' ? convertToText(argument) : argument;
|
||||||
|
});
|
||||||
|
logStore += `${args}\n`;
|
||||||
|
error(...args);
|
||||||
|
};
|
||||||
|
const bundle = await (await fetch('/test__test.browser.ts.js')).text();
|
||||||
|
try {
|
||||||
|
// tslint:disable-next-line: no-eval
|
||||||
|
eval(bundle);
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
setTimeout(() => {
|
||||||
|
console.log(globalThis.testdom);
|
||||||
|
done.resolve();
|
||||||
|
}, 5000);
|
||||||
|
await done.promise;
|
||||||
|
return logStore;
|
||||||
|
}
|
||||||
|
);
|
||||||
await plugins.smartdelay.delayFor(1000);
|
await plugins.smartdelay.delayFor(1000);
|
||||||
await this.smartbrowserInstance.stop();
|
await this.smartbrowserInstance.stop();
|
||||||
console.log(`${cs('=> ', 'blue')} Stopped ${cs(fileNameArg, 'orange')} chromium instance.`);
|
console.log(`${cs('=> ', 'blue')} Stopped ${cs(fileNameArg, 'orange')} chromium instance.`);
|
||||||
|
Loading…
Reference in New Issue
Block a user