Skip to content

Commit

Permalink
chore: 优化build
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuineng committed Nov 7, 2023
1 parent 040ca2f commit 12b0f67
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 20 deletions.
3 changes: 0 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,3 @@ rm -rf ./dist

# 2. tsc compile
./node_modules/.bin/tsc

# 3. copy lib to dist
cp -rf ./lib ./dist
31 changes: 17 additions & 14 deletions lib/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const findElementOrElements = async function(strategy, selector, ctx, many) {

// cache locator
if (strategy === 'xpath') {
this.locator = this.page.locator(selector);
this.locator = (this.pageIframe || this.page).locator(selector);
}
/**
* `css selector` and `xpath` is default
Expand All @@ -80,7 +80,7 @@ const findElementOrElements = async function(strategy, selector, ctx, many) {
}

try {
await this.page.waitForSelector(selector, {
await (this.pageIframe || this.page).waitForSelector(selector, {
state: 'attached',
timeout: 500,
});
Expand All @@ -90,7 +90,7 @@ const findElementOrElements = async function(strategy, selector, ctx, many) {

if (many) {
try {
result = await this.page.$$(selector);
result = await (this.pageIframe || this.page).$$(selector);
} catch (e) {
logger.debug(e);
result = [];
Expand All @@ -109,7 +109,7 @@ const findElementOrElements = async function(strategy, selector, ctx, many) {
return elements;
}

result = await this.page.$(selector);
result = await (this.pageIframe || this.page).$(selector);

if (!result || _.size(result) === 0) {
throw new errors.NoSuchElement();
Expand All @@ -129,21 +129,24 @@ const controllers = {};
*
* @module setFrame
* @return {Promise}
* @param frameElementId
* @param frameElement
*/
controllers.setFrame = async function(frameElementId) {
controllers.setFrame = async function(frameElement) {
let ele;
if (frameElementId) {
ele = await this.elements[frameElementId];
if (frameElement) {
ele = await this.elements[frameElement.ELEMENT];
if (!ele) {
throw new errors.NoSuchElement();
}
this.pageIframe = await ele.contentFrame();
if (!this.pageIframe) {
throw new errors.NoSuchFrame();
}
} else {
// clear pageIframe
this.pageIframe = null;
return null;
}
this.pageIframe = await ele.contentFrame();
if (!this.pageIframe) {
throw new errors.NoSuchFrame();
}
return null;
};

Expand Down Expand Up @@ -294,7 +297,7 @@ controllers.getProperty = async function(elementId, attrName) {
* @return {Promise.<Object>}
*/
controllers.title = async function() {
return this.page.title();
return (this.pageIframe || this.page).title();
};

/**
Expand Down Expand Up @@ -329,7 +332,7 @@ controllers.execute = async function(script, args) {
* @return {Promise.<string>}
*/
controllers.url = async function() {
return this.page.url();
return (this.pageIframe || this.page).url();
};

/**
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"macaca"
],
"files": [
"dist/**/*.js"
"dist"
],
"main": "./dist/lib/macaca-playwright.js",
"main": "./dist/macaca-playwright",
"repository": {
"type": "git",
"url": "https://github.com/macacajs/macaca-playwright"
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
"noUnusedLocals": true,
"stripInternal": true,
"pretty": true,
"allowJs": true,
"declaration": true,
"removeComments": false,
"types": [ "node" ],
"outDir": "./dist/lib"
"outDir": "./dist"
},
"include": [
"lib"
Expand Down

0 comments on commit 12b0f67

Please sign in to comment.