Skip to content

Commit

Permalink
tests ~ only test examples prior to version changes and during prepub…
Browse files Browse the repository at this point in the history
…lication testing

## [why]

Project examples use the distribution code which needs to be up-to-date for correct
results. This is guaranteed, by scripted lifecycle events, during version updates and
prepublication. Additionally, code coverage is confused and incorrectly perceives the code
base as split between 'build' and 'dist' when examples, which load the 'dist' modules, are
measured.
  • Loading branch information
rivy committed Jan 11, 2021
1 parent 9aeffc0 commit 3ed1801
Showing 1 changed file with 63 additions and 60 deletions.
123 changes: 63 additions & 60 deletions test/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,69 +38,72 @@ test('api', (t) => {

// ToDO: add Deno example script checks

test('examples are executable without error (JavaScript)', (t) => {
const egDirPath = 'eg';
const extensions = ['.js', '.cjs', '.mjs'];

// eslint-disable-next-line security/detect-non-literal-fs-filename
const files = fs.readdirSync(egDirPath);

files
.filter((file) => {
return extensions.includes(path.extname(file));
})
.forEach((file) => {
if (settledSupportForESMs || path.extname(file) === '.js') {
const command = 'node';
const script = path.join(egDirPath, file);
const args = [script];
const options = { shell: true, encoding: 'utf-8' };

t.log({ script });

const { error, status, stdout } = spawn.sync(command, args, options);
// test examples with version changes or distribution
if (process.env.npm_config_test_for_dist) {
test('examples are executable without error (JavaScript)', (t) => {
const egDirPath = 'eg';
const extensions = ['.js', '.cjs', '.mjs'];

// eslint-disable-next-line security/detect-non-literal-fs-filename
const files = fs.readdirSync(egDirPath);

files
.filter((file) => {
return extensions.includes(path.extname(file));
})
.forEach((file) => {
if (settledSupportForESMs || path.extname(file) === '.js') {
const command = 'node';
const script = path.join(egDirPath, file);
const args = [script];
const options = { shell: true, encoding: 'utf-8' };

t.log({ script });

const { error, status, stdout } = spawn.sync(command, args, options);

t.log({ error, status, stdout });

t.deepEqual({ error, status }, { error: null, status: 0 });
}
});
});

t.log({ error, status, stdout });
test('examples are executable without error (TypeScript)', (t) => {
const egDirPath = 'eg';
const extensions = ['.js', '.cjs', '.mjs', '.ts'];

t.deepEqual({ error, status }, { error: null, status: 0 });
}
});
});
// eslint-disable-next-line security/detect-non-literal-fs-filename
const files = fs.readdirSync(egDirPath);

test('examples are executable without error (TypeScript)', (t) => {
const egDirPath = 'eg';
const extensions = ['.js', '.cjs', '.mjs', '.ts'];

// eslint-disable-next-line security/detect-non-literal-fs-filename
const files = fs.readdirSync(egDirPath);

files
.filter((file) => {
const extension = path.extname(file);
const name = path.basename(file, extension);
const nameExtension = path.extname(name);
const isDenoTS = extension === '.ts' && nameExtension === '.deno';
return extensions.includes(extension) && !isDenoTS;
})
.forEach((file) => {
if (settledSupportForESMs || path.extname(file) === '.js' || path.extname(file) === '.ts') {
const command = 'node';
const script = path.join(egDirPath, file);
const args = ['node_modules/ts-node/dist/bin.js', script];
const options = { shell: true, encoding: 'utf8' };

const basename = path.basename(file);
files
.filter((file) => {
const extension = path.extname(file);
const name = path.basename(file, extension);
const nameExtension = path.extname(name);

t.log({ script, basename, name, extension, nameExtension });

const { error, status, stdout } = spawn.sync(command, args, options);

t.log({ error, status, stdout });

t.deepEqual({ error, status }, { error: null, status: 0 });
}
});
});
const isDenoTS = extension === '.ts' && nameExtension === '.deno';
return extensions.includes(extension) && !isDenoTS;
})
.forEach((file) => {
if (settledSupportForESMs || path.extname(file) === '.js' || path.extname(file) === '.ts') {
const command = 'node';
const script = path.join(egDirPath, file);
const args = ['node_modules/ts-node/dist/bin.js', script];
const options = { shell: true, encoding: 'utf8' };

const basename = path.basename(file);
const extension = path.extname(file);
const name = path.basename(file, extension);
const nameExtension = path.extname(name);

t.log({ script, basename, name, extension, nameExtension });

const { error, status, stdout } = spawn.sync(command, args, options);

t.log({ error, status, stdout });

t.deepEqual({ error, status }, { error: null, status: 0 });
}
});
});
}

0 comments on commit 3ed1801

Please sign in to comment.