Skip to content

Commit

Permalink
feat: remove console.log, change readme, package files, todos, test p…
Browse files Browse the repository at this point in the history
…orts (#64)
  • Loading branch information
tomek-f authored May 9, 2023
1 parent 945e310 commit 833d54c
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 20 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

> Very simple promise based script loader and JSONP
## Import

[Check dist folder](https://www.npmjs.com/package/simple-load-script?activeTab=code) or package.json

## Usage

### Async/await
Expand Down Expand Up @@ -146,6 +142,10 @@ const defaultConfig = {
- `insertInto` - [CSS selector (an ID, class name, element name, etc.)](https://developer.mozilla.org/en/docs/Web/API/Document/querySelector) to insert the script into. Overrides `inBody` value.
- `removeScript` - remove script tag after load; it's always removed on an error

## Specific import

[Check files](https://www.npmjs.com/package/simple-load-script?activeTab=code) or package.json

## Changelog

[View on github](https://github.com/tomek-f/simple-load-script/blob/master/changelog.md).
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
"check-types": "echo 'checking types…' && tsc && echo '…no type problems'"
},
"files": [
"dist"
"src",
"dist",
"changelog.md"
],
"main": "./dist/index.umd.js",
"umd:main": "./dist/index.umd.js",
Expand Down
7 changes: 3 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ export default function simpleLoadScript(
}
}

console.log({ config, configProcessed });

if (where == null) {
reject(new Error('No DOM element to append script'));
return;
Expand All @@ -71,11 +69,12 @@ export default function simpleLoadScript(
}
resolve(removeScript ? undefined : script);
});
script.addEventListener('error', (err) => {
console.log(err);
script.addEventListener('error', (/* err */) => {
if (removeScript) {
where.removeChild(script);
}
// TODO ? just return err
// TODO ? re-throw err with changed message
reject(new Error('Loading script error'));
});
script.src = url;
Expand Down
6 changes: 3 additions & 3 deletions test/attrs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let page: Page;

beforeAll(async () => {
browser = await chromium.launch({ headless: true });
server = await preview({ preview: { port: 3000 } });
server = await preview({ preview: { port: 3001 } });
page = await browser.newPage();
});

Expand All @@ -25,7 +25,7 @@ test(
'add attrs',
async () => {
try {
await page.goto('http://localhost:3000');
await page.goto('http://localhost:3001');
await page.evaluate(async () => {
await window.simpleLoadScript({
url: '//code.jquery.com/jquery-2.2.3.js',
Expand All @@ -52,7 +52,7 @@ test(
'dom not add attrs',
async () => {
try {
await page.goto('http://localhost:3000');
await page.goto('http://localhost:3001');
await page.evaluate(async () => {
await window.simpleLoadScript({
url: '//code.jquery.com/jquery-2.2.3.js',
Expand Down
10 changes: 5 additions & 5 deletions test/placement.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let page: Page;

beforeAll(async () => {
browser = await chromium.launch({ headless: true });
server = await preview({ preview: { port: 3000 } });
server = await preview({ preview: { port: 3003 } });
page = await browser.newPage();
});

Expand All @@ -25,7 +25,7 @@ test(
'placement head',
async () => {
try {
await page.goto('http://localhost:3000');
await page.goto('http://localhost:3003');
await page.evaluate(async () => {
await window.simpleLoadScript({
url: '//code.jquery.com/jquery-2.2.3.js',
Expand All @@ -46,7 +46,7 @@ test(
'placement body',
async () => {
try {
await page.goto('http://localhost:3000');
await page.goto('http://localhost:3003');
await page.evaluate(async () => {
await window.simpleLoadScript({
url: '//code.jquery.com/jquery-2.2.3.js',
Expand All @@ -68,7 +68,7 @@ test(
'insertInto ok',
async () => {
try {
await page.goto('http://localhost:3000');
await page.goto('http://localhost:3003');
await page.evaluate(async () => {
await window.simpleLoadScript({
url: '//code.jquery.com/jquery-2.2.3.js',
Expand All @@ -90,7 +90,7 @@ test(
'insertInto error',
async () => {
try {
await page.goto('http://localhost:3000');
await page.goto('http://localhost:3003');
await page.evaluate(async () => {
await window.simpleLoadScript({
url: '//code.jquery.com/jquery-2.2.3.js',
Expand Down
6 changes: 3 additions & 3 deletions test/removeScript.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let page: Page;

beforeAll(async () => {
browser = await chromium.launch({ headless: true });
server = await preview({ preview: { port: 3000 } });
server = await preview({ preview: { port: 3004 } });
page = await browser.newPage();
});

Expand All @@ -25,7 +25,7 @@ test(
'removeScript true',
async () => {
try {
await page.goto('http://localhost:3000');
await page.goto('http://localhost:3004');
await page.evaluate(async () => {
await window.simpleLoadScript({
url: '//code.jquery.com/jquery-2.2.3.js',
Expand All @@ -52,7 +52,7 @@ test(
'removeScript false',
async () => {
try {
await page.goto('http://localhost:3000');
await page.goto('http://localhost:3004');
await page.evaluate(async () => {
await window.simpleLoadScript({
url: '//code.jquery.com/jquery-2.2.3.js',
Expand Down

0 comments on commit 833d54c

Please sign in to comment.