Skip to content
This repository has been archived by the owner on Nov 26, 2021. It is now read-only.

Add tests for the javascript program #20

Merged
merged 8 commits into from Aug 2, 2019
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
161 changes: 161 additions & 0 deletions __snapshots__/babel.js
@@ -0,0 +1,161 @@
exports['createConfiguration creates the correct configuration 1'] = {
"filename": "",
"presets": [],
"plugins": [
null,
null
],
"overrides": [
{
"presets": [
[
null,
{
"useBuiltIns": false,
"targets": {
"esmodules": true
},
"modules": "commonjs"
}
]
],
"plugins": [],
"exclude": "./test.src/**"
}
]
}

exports['createConfiguration creates the correct configuration 2'] = {
"filename": "",
"presets": [],
"plugins": [
null,
null
],
"overrides": [
{
"presets": [
[
null,
{
"useBuiltIns": false,
"targets": {
"esmodules": true
},
"modules": "commonjs"
}
]
],
"plugins": [],
"exclude": "./test.src/**"
}
]
}

exports['createConfiguration creates the correct configuration 3'] = {
"filename": "",
"presets": [],
"plugins": [
null,
null
],
"overrides": [
{
"presets": [
[
null,
{
"useBuiltIns": false,
"targets": {
"esmodules": true
},
"modules": "auto"
}
]
],
"plugins": [],
"exclude": "./test.src/**"
}
]
}

exports['createConfiguration creates the correct configuration 4'] = {
"filename": "",
"presets": [],
"plugins": [
null,
null
],
"overrides": [
{
"presets": [
[
null,
{
"useBuiltIns": false,
"targets": {
"esmodules": true
},
"modules": "commonjs"
}
]
],
"plugins": [],
"exclude": "./test.src/**"
}
]
}

exports['createConfiguration creates the correct configuration 5'] = {
"filename": "lol",
"presets": [],
"plugins": [
null,
null
],
"overrides": [
{
"presets": [
[
null,
{
"useBuiltIns": false,
"targets": {
"esmodules": true
},
"modules": "commonjs"
}
]
],
"plugins": [],
"exclude": "./test.src/**"
}
]
}

exports['createConfiguration creates the correct configuration 6'] = {
"filename": "lol",
"presets": [],
"plugins": [
null,
null
],
"overrides": [
{
"presets": [
[
null,
{
"useBuiltIns": false,
"targets": {
"esmodules": true
},
"modules": "auto"
}
]
],
"plugins": [],
"exclude": "./test.src/**"
}
]
}
33 changes: 33 additions & 0 deletions __snapshots__/npm.js
@@ -0,0 +1,33 @@
exports['createManifest creates the same manifest as last time 1'] = {
"browser": "browser.js",
"files": [
"svg/",
"dist/",
"browser.js",
"src/",
"!src/**/*.js",
"main.scss",
"img",
"*.json",
"scss",
"!bower.json",
"!.bower.json"
],
"eslintIgnore": [
"browser.js",
"dist/"
],
"keywords": [
"origami",
"component",
"ft"
],
"name": "@financial-times/o-test-component",
"component": "o-test-component",
"aliases": {
"ft-date-format": "@financial-times/ft-date-format",
"prism": "prismjs",
"pusher": "pusher-js",
"hogan": "hogan.js"
}
}
25 changes: 25 additions & 0 deletions __snapshots__/skeletons.js
@@ -0,0 +1,25 @@
exports['skeletons.js is the same as last time 1'] = {
"browser": "browser.js",
"files": [
"svg/",
"dist/",
"browser.js",
"src/",
"!src/**/*.js",
"main.scss",
"img",
"*.json",
"scss",
"!bower.json",
"!.bower.json"
],
"eslintIgnore": [
"browser.js",
"dist/"
],
"keywords": [
"origami",
"component",
"ft"
]
}
26 changes: 13 additions & 13 deletions lib/babel.js
Expand Up @@ -9,21 +9,21 @@ import babelPresetEnv from "@babel/preset-env"
* A (partial) babel configuration
*
* @typedef {Object} BabelConfiguration
* @property {string} filename the filename currently being operated upon
* @property {[function, any][]} presets a list of presets
* @property {function[]} plugins a list of plugins
* @property {string} exclude paths to exclude
* @property {BabelConfiguration[]} overrides configuration overrides
* @property {babelPluginImportRewrite.Aliases} aliases the rewrites that need to be performed by the import-rewrite plugin
* @property {string} [filename] the filename currently being operated upon
* @property {[function, any][]} [presets] a list of presets
* @property {function[]} [plugins] a list of plugins
* @property {string} [exclude] paths to exclude
* @property {BabelConfiguration[]} [overrides] configuration overrides
* @property {babelPluginImportRewrite.Aliases} [aliases] the rewrites that need to be performed by the import-rewrite plugin
*/

/**
* Options for the createConfiguration function
*
* @typedef {Object} ConfigurationOptions
* @property {"amd" | "umd" | "systemjs" | "commonjs" | "cjs" | "auto" | false} modules the output format to use for modules
* @property {string} filename the filename currently being operated upon
* @property {babelPluginImportRewrite.Aliases} aliases the rewrites that need to be performed by the import-rewrite plugin
* @typedef {Object=} ConfigurationOptions
* @property {"amd" | "umd" | "systemjs" | "commonjs" | "cjs" | "auto" | false} [modules] the output format to use for modules
* @property {string} [filename] the filename currently being operated upon
* @property {babelPluginImportRewrite.Aliases} [aliases] the rewrites that need to be performed by the import-rewrite plugin
*/

/**
Expand All @@ -36,7 +36,7 @@ export function createConfiguration ({
aliases,
modules = "commonjs",
filename = ""
}) {
} = {}) {
return {
filename,
presets: [],
Expand Down Expand Up @@ -68,7 +68,7 @@ export function createConfiguration ({
* @param {ConfigurationOptions} options options to pass to createConfiguration
* @returns {Promise.<string>} the compiled code
*/
let transform = (code, options) =>
export let transform = (code, options = {}) =>
new Promise((resolve, reject) => {
babel.transform(code, createConfiguration(options), (error, result) => {
error ? reject(error) : resolve(result.code)
Expand All @@ -88,7 +88,7 @@ async function buildFile (sourceFile, targetFile, options = {}) {
return Promise.reject(new Error(`sourceFile "${sourceFile}" does not exist`))
}

let sourceCode = await fs.readFile(sourceFile)
let sourceCode = await fs.readFile(sourceFile, "utf-8")
let targetCode = await transform(sourceCode, options)

await fs.writeFile(targetFile, targetCode, "utf-8")
Expand Down
22 changes: 11 additions & 11 deletions lib/npm.js
Expand Up @@ -14,11 +14,11 @@ import origamiComponentNames from "../config/components.js"
/**
* @typedef {Object.<string, any>} ComponentManifest
* @property {string} name the name of the component
* @property {string} description a little something about the component
* @property {string} version the version string
* @property {string} homepage the component's canonical homepage
* @property {Dictionary} dependencies all the component's dependencies
* @property {Dictionary} devDependencies all the component's developer dependencies
* @property {string=} description a little something about the component
* @property {string=} homepage the component's canonical homepage
* @property {Dictionary=} dependencies all the component's dependencies
* @property {Dictionary=} devDependencies all the component's developer dependencies
* @property {string=} license the license the code is released under
*/

Expand All @@ -32,11 +32,11 @@ import origamiComponentNames from "../config/components.js"
* @property {string=} main the component's javascript entry point
* @property {string=} browser the component's browser entry point
* @property {Dictionary=} scripts scripts that can be run with `npm run-script`
* @property {string} component the component's origami name
* @property {string=} component the component's origami name
* @property {Dictionary=} aliases aliases for `babel-plugin-import-rewrite`
* @property {Dictionary=} optionalDependencies optional dependencies
* @property {Dictionary=} peerDependencies peer dependencies
* @property {babel.BabelConfiguration=} babel babel config
* @property {import("./babel").BabelConfiguration=} babel babel config
* @property {string=} browserslist browsers to target
*/

Expand Down Expand Up @@ -112,7 +112,7 @@ export let createDependencyName = name => {
/**
* Get an npm version for a bower package/version
* @param {[string, string]} packageEntry the [name, version] of a single dependency
* @returns {string} the correct target version for the package on npm
* @returns {Promise.<string>} the correct target version for the package on npm
*/
export let createDependencyVersion = async ([name, version]) => {
// if there is a mapping, use that
Expand Down Expand Up @@ -152,7 +152,7 @@ export let createDependencyVersion = async ([name, version]) => {
/**
* Get an npm package entry for a bower package entry
* @param {[string, string]} packageEntry the `[name, version]` of a single dependency
* @returns {[string, string]} the correct target `[name, version]` for the package on npm
* @returns {Promise.<[string, string]>} the correct target `[name, version]` for the package on npm
*/
export let createDependency = async ([name, version]) => {
let npmName = await createDependencyName(name)
Expand All @@ -164,7 +164,7 @@ export let createDependency = async ([name, version]) => {
/**
* Get an npm dependencies object for entries of bower dependencies
* @param {[string, string][]} bowerDependencies the `[name, version]` of the dependencies
* @returns {Dictionary} the dependencies object for the npm manifest
* @returns {Promise.<Dictionary>} the dependencies object for the npm manifest
*/
export let createDependencies = async bowerDependencies => {
let npmDependencies = await Promise.all(
Expand Down Expand Up @@ -203,7 +203,7 @@ export let createAliases = dependencies => {
/**
* Create an npm manifest from a bower manifest
* @param {BowerManifest} bowerManifest the source manifest
* @returns {NpmManifest} the npm manifest
* @returns {Promise.<NpmManifest>} the npm manifest
*/
export let createManifest = async bowerManifest => {
let {
Expand Down Expand Up @@ -240,7 +240,7 @@ export let createManifest = async bowerManifest => {
/**
* Clean an npm manifest before publish
* @param {Promise.<NpmManifest>} manifestPromise a promise resolving to the manifest
* @returns {NpmManifest} the clean npm manifest manifest
* @returns {Promise.<NpmManifest>} the clean npm manifest manifest
*/
export let cleanManifest = async manifestPromise => {
let manifest = {...(await manifestPromise)}
Expand Down