gas-module
v2.2.1
Published
Import local google appscript files written with .js or .ts extension for testing
Downloads
4
Maintainers
Readme
gas-module
Run your google appscript code on your local machine for testing
Install
$ npm install gas-module
Usage
requireFile()
fileName
- name or path of file to be importedoptions
(optional)mocks
- object containing mock variables and functions
requireDir()
dirName
- name or path of directory containing files to be importedrecursion
true
to import files from subdirectories toofalse
to ignore subdirectories
options
(optional)filterExtension
['.js']
for files with .js extension (default if leftundefined
)['.ts']
for files with .ts extension['.js', '.ts']
for files with .js and .ts extensions
mocks
- object containing mock variables and functionsorder
- array of filenames in desired order of execusion, if there is files that is not in the array, it will be executed after
Example
import a file
const { requireFile } = require('gas-module');
const file = requireFile('filename.js');
//run function defined in file
file.myFunction();
import with mocks
const { requireFile } = require('gas-module');
const mock = {
editor: 'vscode',
hotel: 'trivago'
}
const file = requireFile('filename.js', { mocks: mock});
// run function defined in file
file.myFunction();
// use mock varibale
console.log(file.editor);
import a directory
read only .js
files and ignore subdirectories
const { requireDir } = require('gas-module');
const functions = requireDir('directoryname', false, { filterExtension: ['.js']})
// run function defined in any file
functions.myFunction();
read only .ts
files including ones from subdirectories
const { requireDir } = require('gas-module');
const functions = requireDir('directoryname', true, { filterExtension: ['.ts']})
// run function defined in any file
functions.myFunction();
read from both .js
and .ts
files
const { requireDir } = require('gas-module');
const functions = requireDir('directoryname', true, { filterExtension: ['.js', '.ts']})
// run function defined in any file
functions.myFunction();
import with mocks
const { requireDir } = require('gas-module');
const mock = {
editor: 'vscode',
hotel: 'trivago'
}
const file = requireDir('directoryname', false, { mocks: mock});
// run function defined in file
file.myFunction();
// use mock varibale
console.log(file.editor);