Skip to content

Commit

Permalink
Simplify tests
Browse files Browse the repository at this point in the history
  • Loading branch information
niksy committed Mar 25, 2024
1 parent 7e72bef commit 3fb845c
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 148 deletions.
8 changes: 4 additions & 4 deletions generators/app/templates/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@
"@babel/plugin-transform-runtime": "^7.2.0",
"@babel/runtime": "^7.2.0"<% } %><% if ( automatedTests ) { %><% if ( !browserModule || (browserModule && integrationTests) ) { %>,
"@babel/register": "^7.0.0"<% } %><% if ( codeCoverage ) { %><% if ( !browserModule && !sassModule ) { %>,
"babel-plugin-istanbul": "^6.0.0"<% } %><% } %><% } %><% } %>,
"rollup": "^4.13.0"<% if ( !transpile && typescript && typescriptMode === 'full' ) { %>,
"@rollup/plugin-typescript": "^11.1.6"<% } %><% if ( transpile ) { %>,
"@rollup/plugin-babel": "^6.0.4"<% } %><% if ( bundlingTool === 'rollup' || (transpile && typescript && typescriptMode === 'full') ) { %>,
"babel-plugin-istanbul": "^6.0.0"<% } %><% } %><% } %><% } %><% if ( transpile && (bundleCjs || browserModule) ) { %>,
"rollup": "^4.13.0"<% } %><% if ( transpile && (bundleCjs || browserModule) && typescript && typescriptMode === 'full' ) { %>,
"@rollup/plugin-typescript": "^11.1.6"<% } %><% if ( transpile && (bundleCjs || browserModule) ) { %>,
"@rollup/plugin-babel": "^6.0.4"<% } %><% if ( bundlingTool === 'rollup' || (transpile && (bundleCjs || browserModule) && typescript && typescriptMode === 'full') ) { %>,
"@rollup/plugin-node-resolve": "^15.2.3"<% } %><% if ( bundlingTool === 'rollup' ) { %>,
"@rollup/plugin-commonjs": "^25.0.7",
"rollup-plugin-node-builtins": "^2.1.2",
Expand Down
214 changes: 70 additions & 144 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ describe('New project', function () {
assert.jsonFileContent('package.json', {
type: 'module',
name: 'bella',
main: 'index.js',
module: 'index.js',
exports: {
'.': {
'import': './index.js'
},
'./package.json': './package.json'
},
sideEffects: false,
author: 'Ivan Nikolić <[email protected]> (http://ivannikolic.com)',
files: ['index.js', 'lib/', 'LICENSE.md', 'README.md'],
scripts: {
Expand Down Expand Up @@ -882,8 +891,7 @@ describe('Transpile', function () {
prepublishOnly: 'npm run build'
},
devDependencies: {
'rollup': '^4.13.0',
'@babel/preset-env': '^7.12.1'
'@babel/cli': '^7.2.3'
}
});
});
Expand All @@ -905,6 +913,52 @@ describe('Transpile', function () {
});
});

describe('Transpile, source maps', function () {
before(function () {
return helpers
.run(generatorPath)
.withAnswers({
automatedTests: false,
transpile: true,
sourceMaps: true,
changelog: false
})
.toPromise();
});

it('should create necessary files', function () {
assert.file(['.babelrc', 'rollup.config.js']);
});

it('should fill package.json with correct information', function () {
assert.jsonFileContent('package.json', {
main: 'esm/index.js',
module: 'esm/index.js',
exports: {
'.': {
'import': './esm/index.js'
},
'./package.json': './package.json'
},
sideEffects: false,
files: ['esm/'],
scripts: {
build: "babel '{index,lib/**/*}.js' --out-dir esm/ --source-maps true",
prerelease:
'npm run lint && npm run build && npm run module-check',
prepublishOnly: 'npm run build'
},
devDependencies: {
'@babel/cli': '^7.2.3'
}
});
});

it('should add proper data to .gitignore', function () {
assert.fileContent('.gitignore', 'esm/');
});
});

describe('Transpile, browser module', function () {
before(function () {
return helpers
Expand Down Expand Up @@ -941,13 +995,25 @@ describe('Transpile, with automated tests and code coverage', function () {
.withAnswers({
automatedTests: true,
codeCoverage: true,
transpile: true
transpile: true,
nodeEngineVersion: 18
})
.toPromise();
});

it('should fill .babelrc with correct information', function () {
assert.jsonFileContent('.babelrc', {
presets: [
[
'@babel/preset-env',
{
modules: false,
targets: {
node: '18'
}
}
]
],
env: {
test: {
plugins: ['babel-plugin-istanbul']
Expand Down Expand Up @@ -1002,81 +1068,7 @@ describe('Transpile, browser module, with automated tests and code coverage', fu
});
});

describe('ES Modules', function () {
before(function () {
return helpers.run(generatorPath).toPromise();
});

it('should create necessary files', function () {
assert.file(['index.js']);
});

it('should fill package.json with correct information', function () {
assert.jsonFileContent('package.json', {
main: 'index.js',
module: 'index.js',
exports: {
'.': {
'import': './index.js'
},
'./package.json': './package.json'
},
sideEffects: false,
files: ['index.js'],
scripts: {
prerelease: 'npm run lint && npm run module-check'
}
});
});

it('should add proper data to .gitignore', function () {});
});

describe('ES Modules, transpile', function () {
before(function () {
return helpers
.run(generatorPath)
.withAnswers({
transpile: true
})
.toPromise();
});

it('should create necessary files', function () {
assert.file(['.babelrc', 'rollup.config.js']);
});

it('should fill package.json with correct information', function () {
assert.jsonFileContent('package.json', {
main: 'esm/index.js',
module: 'esm/index.js',
exports: {
'.': {
'import': './esm/index.js'
},
'./package.json': './package.json'
},
sideEffects: false,
files: ['esm/'],
scripts: {
build: "babel '{index,lib/**/*}.js' --out-dir esm/ --source-maps true",
prerelease:
'npm run lint && npm run build && npm run module-check',
prepublishOnly: 'npm run build'
},
devDependencies: {
rollup: '^4.13.0',
'@rollup/plugin-babel': '^6.0.4'
}
});
});

it('should add proper data to .gitignore', function () {
assert.fileContent('.gitignore', 'esm/');
});
});

describe('ES Modules, transpile, bundle CommonJS', function () {
describe('Transpile, bundle CommonJS', function () {
before(function () {
return helpers
.run(generatorPath)
Expand Down Expand Up @@ -1108,72 +1100,6 @@ describe('ES Modules, transpile, bundle CommonJS', function () {
});
});

describe('ES Modules, automated tests', function () {
before(function () {
return helpers
.run(generatorPath)
.withAnswers({
automatedTests: true,
codeCoverage: false,
nodeEngineVersion: 8
})
.toPromise();
});

it('should fill package.json with correct information', function () {
assert.jsonFileContent('package.json', {
scripts: {
lint: "eslint '{index,lib/**/*,test/**/*}.js'",
test: "mocha 'test/**/*.js'",
'test:watch': 'npm test -- --watch'
}
});
});
});

describe('ES Modules, automated tests, code coverage, transpile', function () {
before(function () {
return helpers
.run(generatorPath)
.withAnswers({
automatedTests: true,
codeCoverage: true,
transpile: true,
nodeEngineVersion: 18
})
.toPromise();
});

it('should fill package.json with correct information', function () {
assert.jsonFileContent('package.json', {
scripts: {
lint: "eslint '{index,lib/**/*,test/**/*}.js'",
test: "NODE_OPTIONS='--experimental-loader=@istanbuljs/esm-loader-hook --no-warnings' BABEL_ENV=test nyc mocha --require @babel/register 'test/**/*.js' && nyc check-coverage",
'test:watch': 'nodemon --exec npm test'
},
devDependencies: {
nodemon: '^2.0.6'
}
});
});

it('should fill .babelrc with correct information', function () {
assert.jsonFileContent('.babelrc', {
presets: [
[
'@babel/preset-env',
{
modules: false,
targets: {
node: '18'
}
}
]
]
});
});
});

describe('Node engine version', function () {
before(function () {
return helpers
Expand Down

0 comments on commit 3fb845c

Please sign in to comment.