forked from runtypes/runtypes
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
3,768 additions
and
2,193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,4 @@ npm-debug.log* | |
.DS_Store | ||
|
||
.size-snapshot.json | ||
funtypes-0.0.0.tgz |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
const { spawnSync } = require('child_process'); | ||
const { mkdtempSync, writeFileSync, readdirSync, mkdirSync } = require('fs'); | ||
const { tmpdir } = require('os'); | ||
const { join, resolve, relative } = require('path'); | ||
|
||
console.info(`$ npm pack`); | ||
inheritExit(spawnSync(`npm`, [`pack`], { cwd: join(__dirname, `..`), stdio: `inherit` })); | ||
|
||
const OUTPUTS = [ | ||
{ | ||
name: `test.cjs`, | ||
header: [ | ||
`const assert = require('assert');`, | ||
`const t = require('funtypes');`, | ||
`const r = require('funtypes/readonly');`, | ||
], | ||
}, | ||
{ | ||
name: `test.mjs`, | ||
header: [ | ||
`import assert from 'assert';`, | ||
`import * as t from 'funtypes';`, | ||
`import * as r from 'funtypes/readonly';`, | ||
], | ||
}, | ||
]; | ||
|
||
const assertions = [ | ||
...[`Readonly`, `Object`, `Record`].flatMap(n => [ | ||
`assert(typeof t.${n} === 'function');`, | ||
`assert(typeof r.${n} === 'function');`, | ||
]), | ||
`assert(t.Object({}).isReadonly === false)`, | ||
`assert(r.Object({}).isReadonly === true)`, | ||
]; | ||
|
||
const dir = mkdtempSync(join(tmpdir(), `funtypes`)); | ||
for (const { name, header } of OUTPUTS) { | ||
writeFileSync( | ||
join(dir, name), | ||
[...header, ``, ...assertions, ``, `console.log("✅ ${name} Import Tests Passed")`, ``].join( | ||
`\n`, | ||
), | ||
); | ||
} | ||
|
||
mkdirSync(join(dir, `src`)); | ||
writeFileSync( | ||
join(dir, `src`, `test.ts`), | ||
[ | ||
`const assert = require('assert');`, | ||
`import * as t from 'funtypes';`, | ||
`import * as r from 'funtypes/readonly';`, | ||
``, | ||
`const schemaA = t.Object({value: t.String});`, | ||
`const schemaB = r.Object({value: t.String});`, | ||
``, | ||
`const valueA = schemaA.parse({value: 'hello world'});`, | ||
`valueA.value = 'updated value';`, | ||
``, | ||
`const valueB = schemaB.parse({value: 'hello world'});`, | ||
`// @ts-expect-error - valueB.value is readonly`, | ||
`valueB.value = 'updated value';`, | ||
``, | ||
`valueA.value = valueB.value`, | ||
``, | ||
...assertions, | ||
``, | ||
`console.log("✅ TypeScript Import Tests Passed")`, | ||
``, | ||
].join(`\n`), | ||
); | ||
|
||
writeFileSync( | ||
join(dir, `tsconfig.json`), | ||
JSON.stringify({ | ||
compilerOptions: { | ||
module: 'CommonJS', | ||
outDir: 'lib', | ||
noImplicitAny: true, | ||
skipLibCheck: false, | ||
strict: true, | ||
isolatedModules: true, | ||
}, | ||
include: ['src'], | ||
}) + `\n`, | ||
); | ||
|
||
writeFileSync( | ||
join(dir, `package.json`), | ||
JSON.stringify({ | ||
name: 'funtypes-test-import', | ||
private: true, | ||
dependencies: { | ||
'@types/node': '^17.0.21', | ||
typescript: '4.0.2', | ||
}, | ||
scripts: { | ||
typecheck: 'tsc --build', | ||
}, | ||
}) + `\n`, | ||
); | ||
|
||
console.info(`$ npm install`); | ||
inheritExit(spawnSync(`npm`, [`install`], { cwd: dir, stdio: `inherit` })); | ||
|
||
const packPath = relative( | ||
join(dir, `package.json`), | ||
resolve(join(__dirname, `..`, `funtypes-0.0.0.tgz`)), | ||
); | ||
console.info(`$ npm install ${packPath}`); | ||
inheritExit(spawnSync(`npm`, [`install`, packPath], { cwd: dir, stdio: `inherit` })); | ||
|
||
for (const { name } of OUTPUTS) { | ||
console.info(`$ node ${join(dir, name)}`); | ||
inheritExit(spawnSync(`node`, [join(dir, name)], { cwd: dir, stdio: `inherit` })); | ||
} | ||
|
||
console.info(`$ npm run typecheck`); | ||
inheritExit(spawnSync(`npm`, [`run`, `typecheck`], { cwd: dir, stdio: `inherit` })); | ||
console.info(`$ node lib/test.js`); | ||
inheritExit(spawnSync(`node`, [`lib/test.js`], { cwd: dir, stdio: `inherit` })); | ||
|
||
function inheritExit(proc) { | ||
if (proc.status !== 0) process.exit(proc.status); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.